Major upgrades now easier than ever
I’m a fan of major upgrades, which I’ve written about before. For 10 lines of XML, you get free and easy upgrades without having to deal with the costs of patching and minor upgrades:
<! -- Major upgrade -- > <Upgrade Id="$(var.UpgradeCode)"> <UpgradeVersion Minimum="$(var.ProductVersion)" OnlyDetect="yes" Property="NEWERVERSIONDETECTED" /> <UpgradeVersion Minimum="1.0.0" IncludeMinimum="yes" Maximum="$(var.ProductVersion)" IncludeMaximum="no" Property="OLDERVERSIONBEINGUPGRADED" /> </Upgrade> <InstallExecuteSequence> <RemoveExistingProducts After="InstallValidate" /> </InstallExecuteSequence> <Condition Message="!(loc.NewerVersionDetected)"> NOT NEWERVERSIONDETECTED </Condition>
Easy enough to cut and paste but it isn’t exactly what I would call expressive—the intent behind the code isn’t obvious, though it can be deduced fairly easily.
WiX can do better.
So, like the last time I tweaked the WiX language, it’s time for a new feature: The MajorUpgrade element encapsulates the most common options for major upgrades and creates the appropriate rows in the Upgrade and LaunchCondition tables and provides a simpler way of specifying the scheduling of the RemoveExistingProducts action. For example, here’s the simplest use:
<MajorUpgrade DowngradeErrorMessage="Can't downgrade." />
Downgrades are blocked by default, which requires you to specify a message for the launch condition message.
MajorUpgrade is a child of the Product element and automatically picks up the UpgradeCode attribute from its parent. That avoids the common duplication of the upgrade code in the Upgrade element.
MajorUpgrade has the following attributes:
<td valign="top"> Downgrades are blocked by default. </td>
<td valign="top"> The launch condition message displayed when a downgrade is detected. </td>
<td valign="top"> Uninstall failures are upgrade failures by default. </td>
<td valign="top"> Manual control over the features installed in the newer product. </td>
<td valign="top"> Manual control over the features removed from the older product. </td>
<td valign="top"> When to schedule the <a href="http://msdn.microsoft.com/en-us/library/aa371197%28VS.85%29.aspx">RemoveExistingProducts</a> action. </td>
For details, see the MajorUpgrade element documentation. The feature ships in WiX v3.5.1315.0 and later.