Create the Installer Class
Create a class that inherits from the System.Configuration.Install.Installer class (you must first add a reference to the System.Configuration.Install.dll
to your project). This class must be public, and it needs to be in one of the assemblies that are installed by your setup, so place it in one of your existing assemblies, or create a new assembly specifically for the custom installer class. Make sure you add its primary output to your setup. You must also add a RunInstallerAttribute(True)
attribute to your installer class. For example:
Override the Install and Uninstall Methods
Public Class MyInstaller
You must override the Install
methods to add the code to perform your custom installation steps. You can include user interaction when necessary; for example, your code can display forms to gather user input or display status and perform whatever custom steps are required for your application setup.
Make sure you call the base implementation of the Install
methods within your overridden methods to ensure that your install executes automatic tasks such as logging to files and installing state recording. To do that call mybase.Install(stateSaver)
Be careful not to reference classes in your application assembles that are outside the assembly in which your installer class residesthey may not be installed yet!
Test Your Install Class
You run the installer utility installutil.exe
(located in the .NET framework directory) from the command line to test your custom installer class. The utility accepts an assembly filename as an argument. You can also execute an uninstall using "/u"
as the first command-line argument. The standard .NET framework 1.1 install places the installer utility on client machines, so you can also use installutil.exe
to repeat setup tasks on client machines or to troubleshoot failed installations. For example, the following code fragment runs an install:
Or to run an uninstall, use:
C:\Source Code\samples\bin>installutil /u
Refer to the MSDN documentation for the installer utility
for more information.
Custom Installer Class Example
Here's a simple example custom installer class that shows how to inherit from the Installer class and override the Install
methods. This sample creates an event log source during the install process and removes it during the uninstall.
Public Class SimpleInstaller
Const EVENTSOURCE_NAME = "DevX Sample"
Public Overrides Sub Install(ByVal stateSaver As _
Dim strAssemblyPath As String
Dim frmSelection As New Forms.Selection
Catch exc As Exception
MsgBox("Error performing installer tasks-" &
exc.ToString, Exclamation, "Example")
Public Overrides Sub Uninstall(ByVal savedState _
Catch exc As Exception
MsgBox("Error performing un-installer tasks-"
& exc.ToString,Exclamation, "Example")