C# – How to persuade a VS2005 msi to upgrade

cinstallationupgradevisual-studio-2005windows-installer

I have a Windows service written in C# using VS2005.

The installation is via a wizard that calls msiexec to install the msi file also created using VS2005.

I am having trouble generating an msi file that will upgrade from one version of the service to another. The wizard program handles detection of the currently installed version, stopping the service, coming up with an appropriate command-line for msiexec and then re-starting the service.

The existing msi has a version property of 1.1.02, the new one is 1.1.03. The product and upgrade codes are identical.

Uninstalling 1.1.02 manually via add/remove programs works fine, as does installing 1.1.03 onto a "clean" system.

Upgrading 1.1.02 to 1.1.03 goes through the motions but the end result is 1.1.02 installed.

The command line that the wizard uses for upgrading is:

msiexec /qb /i "MyProduct.msi" REINSTALL="ALL" REINSTALLMODE="vos"

Where am I going wrong? I'm assuming I must have missed something fairly fundamental…

The fall-back position is to inform customers that they need to manually uninstall 1.1.02 before running the wizard to install 1.1.03 but I'd rather not have to do that.

Edited to add:

Changing the product code (as VS2005 also prompts you to) actually removes the ability to upgrade at all, as it the installer won't let you do a reinstall if that product code hasn't previously been installed.

All it will then let you do is install (and then you get the usual "service already exists" -type message).

Best Answer

There are several things that need to be done to get "upgrades" to work with MSI's if you want to automatically remove the previous version.

First some background information about the mysterious "codes". There are 3 codes (GUID's) associated with an MSI:

  1. Package Code - This identifies a particular version of the MSI installer and should never be reused across builds. It must always be updated.
  2. Product Code - This identifier is used to ID a particular version of the application. It is up to the installer author to decide when to assign a new product code.
  3. Upgrade Code - This identifies the application and should not change through it's lifetime

The Upgrade Code should never change. For you upgrade scenerio, the Product Code must be changed for each version. Additionally, as you mentioned, you must bump the version number. The Product Code and Upgrade Code can be found by selecting your setup project and going to the Properties Window. The Package Code is hidden in Studio and will always be updated.

The item you are probably missing, is that you also need to set the RemovePreviousVersions setting in the Properties Window to true.

Related Topic