Tuesday, 6 January 2009

WiX Script for Major Upgrades

On the WiX mailing list recently there have been several requests for information about upgrades, this post presents a very basic script that has all the elements necessary to handle a major upgrade.

<?xml version="1.0" encoding="UTF-8"?>
Simple WiX template - This example installs a file in to a directory.

<!-- This is application version number, update for each release -->
<?define Version = "1.0.0" ?>
<?define UpgradeCode = "2CFB7959-56C1-4968-94DB-A8FA212B0FA2" ?>

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="Simple WiX template $(var.Version)" Language="1033"
Version="$(var.Version)" Manufacturer="ACME Corporation"
<Package Description="Simple WiX template Installation" InstallerVersion="200" Compressed="yes" />

<Condition Message="A later version of [ProductName] is already installed.">NOT NEWERVERSIONDETECTED</Condition>

<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="INSTALLDIR" />

<Feature Id="DefaultFeature" Level="1" ConfigurableDirectory="TARGETDIR">
<ComponentGroupRef Id="Test" />

<Upgrade Id="$(var.UpgradeCode)">
<UpgradeVersion Minimum="$(var.Version)" OnlyDetect="yes" Property="NEWERVERSIONDETECTED" />
<UpgradeVersion Minimum="0.0.0" Maximum="$(var.Version)"
IncludeMinimum="yes" IncludeMaximum="no"

<Media Id="1" Cabinet="contents.cab" EmbedCab="yes" />

<UIRef Id="WixUI_ErrorProgressText" />

<FindRelatedProducts Before="LaunchConditions" />
<RemoveExistingProducts After="InstallValidate" />

<FindRelatedProducts Before="LaunchConditions" />

For information on the FindRelatedProducts scheduling see here: LaunchConditions, FindRelatedProducts and Downgrades.

Useful links:
Patching and Upgrades
Paying for upgrades


Unknown said...

Thanks for posting this: I found it helpful.

Building on what you did here, I wanted to make it possible to do an upgrade from one daily build to the next. I found that the ingredients for this were:

* Make sure Product Id is set to "*" - as you did
* In the first UpgradeVersion tag, set IncludeMinimum="no"
* In the second UpgradeVersion tag, sete IncludeMaximum="yes"

Neil Sleightholm said...

Assuming that your version number changes every day the code should work as is i.e. day 1 - 1.0.0, day 2 - 1.0.1.

The NEWERVERSIONDETECTED should be IncludeMinimum="yes" (which is the default) so that if the install is rebuilt with the same version number it won't install.

If you set IncludeMaximum="yes" for OLDERVERSIONBEINGUPGRADED you will get an ICE61 error.

If you follow the WiX users mailing list keep an eye out for my next post, I am just about to find out why IncludeMaximum="yes" is bad.

Unknown said...

Interesting. I do indeed get the ICE61 warning, as you say.

The thing is, that I don't update the third digit of the the version number every day - we only update that once for each bug-fix release.

What is the reasoning behind preventing an install when a rebuild is done with the same version number?

I'll be interested to find out why IncludeMaximum is bad. I wonder if it has something to do with when in the install process older versions are removed? Since we have a light-weight installer, I've scheduled this to happen right at the beginning. I can imagine if you scheduled it at the end you would effectively be removing what you just installed!

Neil Sleightholm said...

For a major upgrade 3 things should change: ProductId, PackageId and Version. I am trying to side step this to get round the problem that Windows Installer only uses 3 part version number.

Kevin McCracken said...


Thank you very much for your contributions on this subject. I am somewhat new to WIX, and found your suggestions to be very helpful.

Alex Cater said...

<Property Id="OLDERVERSIONBEINGUPGRADED" Secure="yes" />

Is not required as WiX automatically appends the property specified in the Property field of each UpgradeVersion element to the SecureCustomProperties property.

Neil Sleightholm said...

You are correct, I will update the script.

Anonymous said...

Images does not display, can you fix them?

Neil Sleightholm said...

Which images?