Ken Kopczyk

Hurdles in .NET Development

MSI Upgrade Removes Necessary Registry Entries! Help!

Posted by Ken on December 13, 2010

Using a Visual Studio “Setup Project” is a quick and easy way to create a simple MSI installation package. Creating a basic installation package is as easy as selecting the items you want to package (exe/dll within your solution, Assemblies, miscellaneous files, etc), choosing their location (system directory, GAC, Desktop, etc) and flipping a couple of options within the Properties window. You can even have it automatically register assemblies if necessary. This is very helpful if you have to deal with older COM components.

Properties window for a Visual Studio Setup Project

After releasing an initial MSI version 1.0, I started running into issues with my 2.0 upgrade MSI. My intent was to have the new MSI remove all components/files installed by the 1.0 MSI, and then install the 2.0 components. I thought this would be accomplished by flipping the “RemovePreviousVersions” property to true, incrementing the “Version” property and changing the “ProductCode.”  However, I’ve experienced issues where registry entries were getting removed and files were not getting updated as they should. Turns out the MSI needed additional TLC which the “Setup Project” GUI within Visual Studio could not provide. Enter Orca.

Orca is a database table editor that gives you full access to all the settings within the MSI.  It provides much more granule control than what Visual Studio gives you.  It is available as part of the Windows SDK Components for Windows Installer Developers.  To fix all my upgrading issues, I used the following steps:

  1. In the Properties table, I’ve added the key/value pair: REINSTALLMODE = amus.  See MSDN for more info on this property.
  2. In the InstallExecuteSequence table, I modified the Sequence of the RemoveExistingProducts Action to come just before the InstallValidate Action. This is per the advice of Adrian Accinelli from the following thread: MSDN MSI Forum
  3. Finally, I checked to make sure the rows in the Upgrade table were correct. I modified it so that the row with ActionProperty = PREVIOUSVERSIONSINSTALLED had the version min set to, version max set to the version number of the previous version, and the Attributes set to 768. I modified the row with ActionProperty = NEWERPRODUCTFOUND to have version min set to the version number of your upgrade, version max set to blank, and Attributes set to 258. See here for details of the Attributes column.

Step 3: The upgrade table of an MSI

One thing to note:  Any of those three steps can be automated using Post-Build events, Cscript (built into Windows) and WiRunSQL.vbs, a VBscript included in the Windows SDK Components for Windows Installer Developers.  Here is an example using step #1 from above:

Cscript WiRunSQL.vbs foo.msi “INSERT INTO Property (Property.Property, Property.Value) VALUES (‘REINSTALLMODE’,’amus’)”

The moral of this story is:  A Visual Studio Setup Project is a quick and dirty way to create an MSI.  However, better tools are required if your installation becomes slightly more complicated.  Orca, WiRunSQL, and WiX are all helpful tools for building and maintaining MSIs.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: