Поделиться через


How to Upgrade Software with a Windows Installer Package

One of the things that you often want to do when creating a Windows Installer using WiX is to uninstall the existing product before installing the new one.  This is referred to as doing a "major upgrade".  The way to pull this off is to add the following WiX snippet to your .wxs file:

 <Wix xmlns="https://schemas.microsoft.com/wix/2006/wi" xmlns:netfx="https://schemas.microsoft.com/wix/NetFxExtension">
  <Product 
    Id="*" 
    ...
    UpgradeCode="35ED4D41-BA5F-4598-8266-A1B9EB512345">
    ...
    <Upgrade Id="35ED4D41-BA5F-4598-8266-A1B9EB512345">
      <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="InstallInitialize" />
    </InstallExecuteSequence>

Note the product's Id attribute set to "*" so you don't forget to change it each time, but make sure the UpgradeCode stays the same forever.  You could change the IncludeMaximum attribute to "yes" on the second UpgradeVersion element for debug builds so that you can continuously reinstall during development, even though your version number may not be changing.  However I don't recommend you ship that way, because you want repair existing installations by default not uninstall/install them.

My thanks to Bob Arnson on the WiX team for providing this tip.