Someone recently asked how to support uninstall in dotNetInstaller, specifically with MSI components. It’s a question that comes up frequently, and it’s a powerful feature of dotNetInstaller. We use it for a very large bootstrapper (1.2GB) across a dozen installers, including some big ones that we didn’t write (IBM Cognos).
While the documentation explains the basics, it’s a bit thick. This is a step-by-step tutorial.
The Basics
Create an Installer
Create a basic WIX MSI, MySetup. I’ve added a dummy component and feature to it.
Create a Bootstrapper
Create a simple bootstrapper that installs MySetup.msi. Add an Installed Check and package the MSI in the bootstrapper.
Note that the GUID matches the UpgradeCode in the WIX MSI we have created above.
Link the Bootstrapper
You can now link the bootstrapper with InstallerLinker. We’ll use MSBuild to automate our build.
Run the Bootstrapper
You can run the bootstrapper and MySetup.msi will be installed. Run the bootstrapper again, and it will offer you to uninstall MySetup.msi. It has detected that it’s already installed and will automatically switch to uninstall mode. This will uninstall the application and it works.
Great! I have an uninstaller, right?
Not really. The problem with what we have created is that the bootstrapper needs to be left on the machine after installation. With my 1.2GB bootstrapper that’s really not an option. That’s also a chicken-and-egg problem, because the bootstrapper needs to contain itself to be included in an installer to be used for uninstall if we wanted to create, for example a shortcut.
What we need is a bootstrapper that can do uninstall, and that can be included in MySetup.msi, installed and used post-installation.
Generate an Uninstaller
Save the Product Code
An MSI can be installed with msiexec /i MySetup.msi
and can be uninstalled with msiexec /x {product id}
. Let’s augment the MSI and write the product code for the MSI into registry. The bootstrapper will be able to look for that value to execute the msiexec /x
command.
Use the Product Code
It is now possible to use this product code from registry for the uninstall package, a nice feature of DNI.
Including the Bootstrapper in the MSI
First, let’s build this bootstrapper without embedded files. It’s the same command line with /Embed-
. We’ll place the output to Uninstall.exe.
Include Uninstall.exe in the MSI and create an uninstall shortcut to the MSI. The shortcut runs Uninstall.exe /x
, forcing uninstall.
Once installed, the shortcut can be used to uninstall the application. During uninstall the MSI component will fetch the product id from registry and invoke msiexec /x
.
Links
- Source Code, run
build all /p:Configuration=Release
to build