Making an upgrade MSI using WIX

Don’t work too much, give time to your family, and friends – how?

Check out my new blog at: http://www.ranbeermakin.com/

Now the blog: There were no ‘good’ references on how to make an upgrade MSI using Windows Installer XML. I found bits from here and there, and with experiments was able to successfully create an upgrade MSI.

This document is a quick reference for those who want to make a Major upgrade MSI. Let’s get to work now!

An upgrade installs the current version and removes any previously installed versions. When removing a previously installed version if you do not want some custom actions to be executed, a property, UPGRADINGPRODUCTCODE, can be used.This property is set when a previously installed version is getting removed.

In order to detect installed versions the following code is used:

<UpgradeVersion OnlyDetect='no' Property='PROJECT_UPGRADE'
Maximum='1.1.9.17' IncludeMaximum='no' RemoveFeatures='all'/>

The above code snippet means any version less than 1.1.9.17 will be detected (the product ID of the versions detected will be appended to the property PROJECT_UPGRADE), and removed (specified by OnlyDetect=’no’).

In order to detect if this version is not going to downgrade an already existing version the following code is used:

<UpgradeVersion OnlyDetect='yes' Property='PROJECT_DOWNGRADE'  Minimum='1.1.9.17' IncludeMinimum='no'/>

The above code snippet means any version more than 1.1.9.17 will be detected (specified by OnlyDetect=’yes’) and product IDs of all such versions will be appended to the property PROJECT_DOWNGRADE.If this property gets set, it means this version will downgrade an already existing version.

The detection of such products is based on UpgradeCode specified in the Product section and the version range specified by Maximum and Minimum attributes of UpgradeVersion element.

<Product Id='PUT-A-GUID' Name='YOUR PRODUCT NAME' Language='1033' Version='1.1.9.17'UpgradeCode='PUT-A-GUID-FOR-UPGRADE-CODE' Manufacturer='YOUR MANUFACTURER'>

That said, UpgradeCode is kept same across releases only if different releases should not co-exist.

Three things need to be modified for a major upgrade MSI (Note: These three things should be different from the upgradeโ€™s parent MSI)

  1. Product ID
  2. Package ID
  3. Version – Version number till 3rd digit is relevant. Any change in the last digit of the version will not be considered. That is, version 1.1.0.10 is the same as version 1.1.0.11 for an upgrade. But, version 1.1.0.10 is different from 1.1.1.10!

Combining the pieces together:

<Product Id='PUT-A-GUID' Name='YOUR PRODUCT NAME'  Language='1033' Version='1.1.9.17' UpgradeCode='PUT-A-GUID-FOR-UPGRADE-CODE' Manufacturer='PRODUCT'S MANUFACTURER'> <Package Id='PUT-A-GUID' Description='YOUR PRODUCT DESCRIPTION' Comments='Version 1.1.9.17' Manufacturer='YOUR MANUFACTURER' InstallerVersion='200' Compressed='yes'/>  <Upgrade Id='A-GUID-SHOULD-BE-SAME-AS-UPGRADE-CODE> <UpgradeVersion OnlyDetect='no' Property='PROJECT_UPGRADE' Maximum='1.1.9.17' IncludeMaximum='no' RemoveFeatures='all'/> <Property Id='PROJECT_UPGRADE' Secure='yes'/> <UpgradeVersion OnlyDetect='yes' Property='PROJECT_DOWNGRADE' Minimum='1.1.9.17' IncludeMinimum='no'/> <Property Id='PROJECT_DOWNGRADE' Secure='yes'/>
</Upgrade>  <CustomAction Id='NoDownGrade' Error='A later version of [ProductName] is already installed.' /> <InstallExecuteSequence>  <LaunchConditions After='AppSearch'></LaunchConditions>
 <Custom Action='NoDownGrade' After='FindRelatedProducts'> <![CDATA[PROJECT_DOWNGRADE]]></Custom>  <RemoveExistingProducts After='InstallFinalize'/> </InstallExecuteSequence> </Product>

Phew! It was pain formatting the code! Anyways, I hope how to make a major upgrade is clear now. For other types of upgrade and guidelines refer msdn.

If you feel this blog has helped you in anyway, then please comment. I would appreciate if you comment even if this blog entry didn’t solve your problem (and how it didn’t). I would be more than happy to look into them.

16 thoughts on “Making an upgrade MSI using WIX

  1. The downgrade error is shown after the UI (in my installer). Is there any possibility the error is shown just after the initializacion of the installer before the UI sequence and dialogs?

  2. @Rollo Tomasi

    Thanks. I have joined pieces from here and there. MSDN would be best for references.

    @Cruz
    I do not think as ‘NoDownGrade’ custom action can only be called after action ‘FindRelatedProducts’. Let me know too if you find any solutions to it.

  3. Helpful in terms of the major upgrade – it works great for an installer without a UI… How does one add a dialog that triggers for a major upgrade instead of a minor (resume)?

  4. Thanks for the post but i’m still experiencing some issues. I pretty much started off with a blank wix project and used all the examples here.

    What i’m trying to do is keep the same product ID and upgrade code (as I need to) but when installing a new version, get the MSI to auto remove the existing version.

    Following the examples above, I always get the error “Another product is already installed”.

    Any suggestions would be great.

  5. @Sol young

    Doesn’t major upgrade work for an installer with UI? I didn’t understand your question, though I’ll try answering it.
    May be can create an EXE and this EXE will launch the MSI with major upgrade! ๐Ÿ™‚

    @Dave
    No Dave. For a major upgrade you need to change the productID. Otherwise you’ll keep getting the error that you are experiencing. And, you are experiencing this error because you must have changed its package ID.

    So, for major upgrade the crux of the matter is to change product, package ids and the version. And, yes, do not change upgrade code ๐Ÿ™‚

  6. I set the RemoveFeatures property to newly selected features. It is removing the newly selected features.as of now it is fine with me.
    But in Add or Remove programs there are 2 entries with older version and Newer version.
    I want only the newer version.

  7. So, I have a question about what goes on behind the scenes. When you are doing a major upgrade, then the installer will remove the previous version. I understand that part. Say I have two versions; the old one 1.0, and the new one, 2.0. When I create the upgrade package for 2.0, if I have done it correctly then 1.0 will be uninstalled. Will doing this call the uninstall based on the components in 1.0 or 2.0. I ask because I worry about orphaning files. If I remove a file in 2.0 I need to make sure that it won’t still be there after the upgrade.

Leave a comment