Wednesday, October 31, 2007

Custom Actions on Vista with visual studio.net 2003

One handy feature of Visual Studio.net 2003 Deployment projects is support for Custom Actions. These can be either executables or libraries that can be invoked during an install (or uninstall).

There are several predefined Installation components, derived from System.Configuration.Install.Installer, for handling things like installing services. You can implement custom actions as Installation Components (by deriving from Installer, specifying a few attributes, etc...) to get built-in support from both the VS.net 2003 Deployment project and the .NET SDK installutil.exe program.

The problem I ran into on Vista was that the install was being cancelled by Vista's Data Execution Prevention (DEP). Changing from a dll custom action to an EXE still resulted in the execution being cancelled (though, not by DEP). It turns out that there is a bug in the way VS.Net 2003 deployment projects construct the MSI install package.

To fix this, an application manifest needs to be embedded in the custom action executable. This manifest specifies a requiredPrivileges token (we're using "asInvoker") that is needed for the custom action executable to run during an install. Unfortunately, on VS.Net 2003, I haven't found an easy way to embed the application manifest in the custom action executable. One way of embedding this manifest in the executable is to open the executable in visual studio and manually import the manifest. An example, with steps, follows.

The manifest itself is taken from the "Vista Developer Story" (step 6).

To embed this manifest in the executable:

  1. Build the executable

  2. In visual studio use File - Open to open up the executable.

  3. Right click the executable and choose "Add Resource"

  4. Choose "Import"

  5. enter RT_MANIFEST then click ok

  6. Change the ID property to 1

  7. Save the executable.

  8. Leave the executable open so that the deployment project can't overwrite the executable.

This procedure will need to be done each time to update the embedded resource

No comments :

Post a Comment