How to register custom components for multiple products


Summary The following topic discusses how a developer can take an existing component and register it for ArcGIS Desktop and ArcGIS Engine.

In this topic


About registering custom components for multiple products

Before ArcGIS 10, a developer could create a component that worked for ArcGIS Desktop and ArcGIS Engine by making the Component Object Model (COM) visible and adding the correct category registration code. The following code example shows a command that is registered for ArcMap and ArcGIS Engine:
[VB.NET]
Private Shared Sub ArcGISCategoryRegistration(ByVal registerType As Type)
Dim regKey As String = String.Format("HKEY_CLASSES_ROOT\CLSID\{{{0}}}", registerType.GUID)
MxCommands.Register(regKey)
ControlsCommands.Register(regKey)
End Sub
[C#]
private static void ArcGISCategoryRegistration(Type registerType)
{
    string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}",
        registerType.GUID);
    MxCommands.Register(regKey);
    ControlsCommands.Register(regKey);
}
The previous code example would have been executed when the developer registered their component using RegAsm, and in turn, the component placed into the appropriate category. When ArcMap or ArcGIS Engine starts, it recognized the command and loaded it.
Now, ArcGIS products no longer blindly read components from the system registry. Developers need to use the new ESRIRegAsm utility to register their components for ArcGIS by adding the appropriate ESRIRegAsm syntax to their solution (following the steps outlined in Migrating ArcGIS 9.3 Desktop and Engine custom components to ArcGIS 10), or remember to manually call ESRIRegAsm before using or debugging their application.
Developers are still required to insert the component category registration code in their custom components. ESRIRegAsm relies on the component category registration code to properly generate the configuration file.
In addition, ArcGIS products can live independently of one another, which means a machine could potentially have ArcGIS Desktop and ArcGIS Engine installed in two different locations. Hence, a component shared by one or more ArcGIS products, require explicit registration per target product. 
Without proper registration or registrations, developers can run into a problem where their component is not being discovered by an application or only by a single application. Often times, this can occur when using or debugging an ArcGIS 9.x sample, or when migrating older applications.
For a custom component to work for ArcGIS Desktop and ArcGIS Engine, the component must be registered separately using ESRIRegAsm (once for ArcGIS Desktop, then again for ArcGIS Engine). This creates the appropriate configuration file for each target ArcGIS product, if present, to load the component. 

Registering shared components

The following MSBuild Extensible Markup Language (XML) code example shows how to use ESRIRegAsm in a Visual Studio C# or VB .NET project file to register shared components for ArcGIS Desktop and ArcGIS Engine:
[XML]
<Target Name="BeforeClean">
  <Exec
    WorkingDirectory="$(CommonProgramFiles)\ArcGIS\bin"
    Command="esriRegasm.exe &quot;$(TargetPath)&quot; /p:Engine /u /s"
    Condition="Exists('$(TargetPath)')"
    ContinueOnError="true"/>
  <Exec
    WorkingDirectory="$(CommonProgramFiles)\ArcGIS\bin"
    Command="esriRegasm.exe &quot;$(TargetPath)&quot; /p:Desktop /u /s"
    Condition="Exists('$(TargetPath)')"
    ContinueOnError="true"/>
</Target>
<Target Name="AfterBuild">
  <Exec
    ContinueOnError="true"
    WorkingDirectory="$(CommonProgramFiles)\ArcGIS\bin"
    Command="esriRegasm.exe &quot;$(TargetPath)&quot; /p:Engine /s"/>
  <Exec
    ContinueOnError="true"
    WorkingDirectory="$(CommonProgramFiles)\ArcGIS\bin"
    Command="esriRegasm.exe &quot;$(TargetPath)&quot; /p:Desktop /s"/>
</Target>
Do the following steps to edit the Visual Studio C# or VB .NET project file:
  1. Right-click the project in Visual Studio and select Unload Project. 
  2. Right-click the project file again and select Edit <Project Name>.  

    For more information, see Migrating ArcGIS 9.3 Desktop and Engine custom components to ArcGIS 10.
When creating custom components using the integrated development environment (IDE) integration tools, the ArcGIS Add Class Wizard only adds the initially selected ArcGIS target product to your class library project. See the following screen shot of the ArcGIS Add Class Wizard:
In addition, if the specified ArcGIS product is not installed on the machine, the IDE integration generated project file issues a build error if ESRIRegAsm fails to register your project assembly. The ContinueOnError attribute shown in the previous XML code example, helps to bypass this type of build error. Instead, a build warning is issued. Hence, developers should always review the list of build warnings to check if any of the ESRIRegAsm steps failed.


See Also:

Migrating ArcGIS 9.3 Desktop and Engine custom components to ArcGIS 10
ESRIRegAsm utility
How to register COM components
Registering classes in COM component categories




Development licensing Deployment licensing
Engine Developer Kit Engine Runtime
ArcInfo ArcInfo
ArcEditor ArcEditor
ArcView ArcView