HOW TO

Deploy custom components created in .NET using Visual Studio.NET Setup and Deployment project

Last Published: April 25, 2020

Summary

.NET provides the ability to add code to classes that will be called when REGASM is called on the assembly. This allows components to handle their own category registration. When installing assemblies by way of a Windows Installer application the self-registration code is not called automatically. To insure the category registration code gets called is by adding an installer class to each project. The installer class will be called during install and unistall of the class, and can be used to call the category registration code. Instructions provided describe how to deploy custom components created in .NET using Visual Studio.NET Setup and Deployment project.

Procedure

The following proceedure outlines a basic deployment using a .NET solution containing one project with one or more COM enabled classes.

For this deployment strategy to work, deployment machines must already have the .NET Framework and ESRI assemblies installed.

  1. In the Visual Studio.NET project, add a New Item: Add an Installer Class item, and name it 'InstallationConfig.vb', or something similar.
  2. Right-click the new class and View Code. Add the directive shown below to use RegistrationServices objects:

    Code:
    Imports System.Runtime.InteropServices

  3. Paste the following code into the body of the class. This is the piece that the setup program calls to correctly register any COM components that the ArcObjects project uses. It also keeps track of the system state during the installation so that a subsequent uninstall will clean the registry:

    Code:
    Public Overrides Sub Install(ByVal stateSaver As System.Collections.IDictionary)
    Try
    MyBase.Install(stateSaver)
    Dim regsrv As New RegistrationServices()
    If Not (regsrv.RegisterAssembly(MyBase.GetType().Assembly, _
    AssemblyRegistrationFlags.SetCodeBase)) Then
    Throw New InstallException("Failed To Register for COM")
    End If
    Catch ex As Exception
    MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error during installation")
    End Try
    End Sub

    Public Overrides Sub Uninstall(ByVal savedState As System.Collections.IDictionary)
    Try
    MyBase.Uninstall(savedState)
    Dim regsrv As New RegistrationServices()
    If Not (regsrv.UnregisterAssembly(MyBase.GetType().Assembly)) Then
    Throw New InstallException("Failed To Unregister for COM")
    End If
    Catch ex As Exception
    MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error during unistallation")
    End Try
    End Sub

  4. Add the Setup project for deploying the application. Right-click on the icon for the solution in the Solution Explorer window and Add a New Project. Select Setup and Deployment Projects > Setup Project.
  5. Immediately look at the Properties for the project. Check the Author, ProductName, Manufacturer, Title, and RemovePreviousVersions [default=False] values.
  6. A. Right-click on the Application Folder icon, then click Add Project Output. From the Project dropdown list select the project to deploy.

    B. In the Solution Explorer, open the file system window by clicking on the Primary output for the project displayed. In the right panel of the window there is a list of all the files that will be included as part of the project output.

    C. Remove the ESRI Primary Interop Assemblies, such as ESRI.ArcObjects.Core.dll, ESRI.ArcObjects.Samples.CatIDs.dll.

    D. Remove stdole.dll
  7. Associate the custom installation steps, the COM registration material that is in your Installer Class code file with the Setup Project. Right-click on the Setup Project icon in the Solution Explorer window and select 'View Custom Actions'.
  8. In the resulting view, right-click on the Install folder icon and select Add Custom Action.
  9. Double-click the Application Folder, then double-click 'Primary output from <AssemblyName> <Version>'. The custom Install Class actions are in this assembly, ane ensures they will be executed as part of the installation.
  10. Repeat steps to the Uninstall folder on the Custom Actions view.
  11. Build both the ArcObjects project and the Setup project. The folder containing the Setup project can be given to another ArcGIS user for execution. This is usually in a folder called Release under the main Setup Project directory.

Article ID:000006209

Software:
  • ArcMap 9 x
  • ArcMap 8 x

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Related Information

Discover more on this topic