Вы находитесь на странице: 1из 2

How to register .

NET components with COM Page 1 of 2

ESRI.com | Support | More ESRI Sites...

Home Documentation Library Discussion Forums Downloads Code Exchange Media Center Conferences

How to register .NET components with COM

Summary
Extending the ArcGIS applications with custom .NET components requires that the .NET Search
classes are made available to the component object model (COM) runtime by registering the
components in the COM registry. The three ways to perform this task are outlined in this Documentation Library
document. In addition, if the component is to be used from a COM development environment,
you may also want to export a type library, which is also outlined in this document. GO
Search Help
Building the project on a development machine
Use: On a development machine

Contents
When you want to register an assembly for COM interop on a development machine, the simplest
Library Home > Extending ArcGIS
way is to open the project in Visual Studio 2005, ensure the project- level Register for COM
Desktop with .NET >
Interop property is set to true, then build the project.
Programming with .NET
To check a project's settings, click Project Properties from the Project menu, select the Build
(C#) or Compile (VB.NET) page, and select the Register for COM Interop check box. MSDN .NET Developer
Centers
Interoperating with COM
Registering by command, using the Regasm utility Binary compatibility
Use: When testing on a different machine and you do not have an installation program System.__ComObject and
casting to strongly typed
RCWs
Sometimes you may want to register an assembly for COM interop without building the project;
How to release COM
for example, when first testing your component or if you do not have access to the assemblies
references
source code.
How to shutdown
In this case, you can use the assembly registration utility Regasm that ships with the .NET ArcGIS .NET applications
Framework Software Development Kit (SDK) or Visual Studio 2005. Regasm will add entries to Working with resources
the registry, which allows a COM (unmanaged) application to consume .NET classes via COM Performance of ArcObjects
interop.
How to implement error
handling
Machines with either Visual Studio 2005 or the freely available .NET Framework Implementing cloning
SDK will have this utility installed and other machines may not; therefore. this is Sample: Clonable object
not a viable solution for general deployment of your components. Implementing persistence
Sample: Cloning an object
Using the Regasm command line utility using persistence
To use the Regasm command line utility: How to cast between
interfaces
If the target machine has Visual Studio installed, open the Visual Studio 2005 command
prompt (the ordinary command prompt will not have the appropriate environment variables Namespaces and ProgIds
set to use this tool). How to register .NET
components with COM
If the target machine does not have Visual Studio installed but does have the .NET
Framework SDK installed, use the SDK command prompt by choosing Programs, then How to register classes in
Microsoft .NET Framework SDK v2.0. If you cannot find it, open a command prompt at the COM component categories
path where Regasm is located. For example, the .NET Framework 2.0 default installation Working with component
path is C:\Windows\Microsoft.NET\Framework\v2.0.50727. categories through the ADF
Assembly versioning and
The following example shows the command used to register the assembly called EditTools with redirection
COM. The full path to the assembly should be given unless the current directory of the command Writing Multithreaded
prompt is the directory where the assembly is located: ArcObjects Code
Working with OLE StdFont
regasm EditTools.dll /codebase and StdPicture classes
Hidden managed classes not
The /codebase parameter is an optional parameter that adds information to the registry appearing in VB.NET
specifying the path on disk of the assembly. If the component is not to be deployed to the global intellisense
assembly cache (GAC), then this option will be required for ArcGIS to find your component
Events
successfully; if the component is installed to the GAC, the option is not required. Regasm has
many other options; for a full list, type regasm /? or refer to Microsoft Developer Network
(MSDN).

Regasm can also be used to unregister assemblies from COM interop, as shown in the following
example:

regasm EditTools.dll /unregister

Using an installation program

http://edndoc.esri.com/arcobjects/9.2/NET/9826f81b-278c-49cc-a912-ab8d86f5e91e.htm 09/03/2010
How to register .NET components with COM Page 2 of 2

Use: When deploying to your user

Finally, you can create an installation program, which will deploy your component and add to the
installation program an automatic registration step that will register your component for COM
interop.

You can create installation programs by using either third- party installation software or using a
Visual Studio Setup Project. For an example of how to create a setup project for a component
using WISE, see How to deploy an application.

Type libraries for managed components

A type library (.tlb) can also be exported that contains information describing the types in the
assembly. You may want to generate a type library for a component if that component will be
used from another development environment, such as within the Visual Basic for Applications
(VBA) environment embedded with the ArcGIS applications. If you want to add custom
commands and tools using the Customize dialog box within the ArcGIS applications, you need to
generate a type library.

Visual Studio will generate this .tlb automatically if you have checked the Register for COM
Interop setting. If you do not have a .tlb for an existing component, one can be generated by
using the Regasm utility and the /tlb option. See the following:

regasm EditTools.dll /tlb:EditTools.tlb

User comments Add your comment

general deployment without an installer using regasm.exe /regfile posted by:


nickseigalcom on Jan 21, 2008 01:17

The MSDN page titled "Assembly Registration Tool (Regasm.exe)" (last seen at
http://msdn2.microsoft.com/en- us/library/tzat5yw6(VS.80).aspx) describes how to use
Regasm.exe in more detail. In particular, you can use the /regfile option to generate a .reg
file that contains the registry entries instead of making the changes directly to the registry.
You can update the registry on any computer by importing the .reg file with the Registry
Editor tool (Regedit.exe). This is quite similar to the "Register" part of the old Compile and
Register (ESRI VB6) Add- In, and provides a a viable solution for general deployment of
your components -- simply send the .reg file along with the .NET assembly (.dll).

http://edndoc.esri.com/arcobjects/9.2/NET/9826f81b-278c-49cc-a912-ab8d86f5e91e.htm 09/03/2010

Вам также может понравиться