Using Your Custom Installer
You need to configure your setup project to recognize your custom installer. First, make sure your installer class is in an assembly that will be deployed with your setup. Next, right-click your setup project, select the view menu, and then click Custom Actions (see Figure 1
|Figure 1. Configuring a Custom Action: You can view or configure custom setup actions using the context menu available by right-clicking on your setup project item in the Solution Explorer.|
You'll see the custom actions editor. Right-click the "Custom Actions" node, and click "Add Custom Action", and then choose the assembly that contains your installer class implementation (see Figure 2
|Figure 2. Adding Custom Actions: From the Custom Actions editor, right-click the "Custom Actions" node, select the "Add Custom Action" menu item, and then choose the assembly containing your installer class.|
Remember to select the assembly that contains your installer class, not the class you want to execute at setup time. The Windows Installer service uses the .NET framework to find all instances of the installer class in your assembly with the RunInstallerAttribute
attribute set to true
and executes each one. You can have multiple installer classes in your assembly.
You can also choose to execute your installer class in only some of the install, commit, rollback, and uninstall phases by adding your installer class to those nodes only (right-click the node you want, rather than the top "Custom actions" node.
Storing Install State Data
Use the stateSaver
argument passed to the Install
method to save information you will need later to perform custom uninstall actions. Having saved such information during the install, you retrieve it for the uninstall via the savedState
argument passed to the Uninstall
method. For example, if you were to prompt the user for the name of an IIS virtual directory that you want the install process to create automatically, you could then store the name of the virtual directory so that you could delete it on uninstall.
In your installer class install()
method, save state like this:
Having saved the virtual directory name during the install process, in your uninstall()
method, you can retrieve it like this:
blnCreate = savedState("VirtualDirectoryName")