This document is archived and information here might be outdated.  Recommended version.


How to register custom components for multiple products (ArcObjects .NET 10.8 SDK)
ArcObjects Help for .NET developers > ArcObjects Help for .NET developers > Developing with ArcGIS > Learning ArcObjects > Extending ArcObjects > How to register custom components for multiple products

How to register custom components for multiple products


Summary
This topic discusses how you can take an existing component and register it for ArcGIS Desktop and ArcGIS Engine.

In this topic


About registering custom components for multiple products

Prior to ArcGIS 10, you 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);
}
This type of code example would have been executed when you registered your component using RegAsm, and in turn, the component would be placed into the appropriate category. When ArcMap or ArcGIS Engine was started, it recognized the command and loaded it.
Now, ArcGIS products no longer blindly read components from the system registry. You need to use the ESRIRegAsm utility to register your components for ArcGIS by adding the appropriate ESRIRegAsm syntax to your solution (following the steps outlined in Migrating ArcGIS 9.3.x and 10 Desktop and Engine custom components to ArcGIS 10.1), or remembering to manually call ESRIRegAsm before using or debugging your application.
You are still required to insert the component category registration code in your 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 requires explicit registration per target product. 
Without proper registration or registrations, you can run into a problem where your 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>
Complete 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, you should always review the list of build warnings to check if any of the ESRIRegAsm steps failed.


See Also:

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




Development licensing Deployment licensing
Engine Developer Kit Engine
ArcGIS Desktop Advanced ArcGIS Desktop Advanced
ArcGIS Desktop Standard ArcGIS Desktop Standard
ArcGIS Desktop Basic ArcGIS Desktop Basic