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=”http://schemas.microsoft.com/wix/2006/wi” xmlns:netfx=”http://schemas.microsoft.com/wix/NetFxExtension”>
<UpgradeVersion Minimum=”$(var.ProductVersion)” OnlyDetect=”yes” Property=”NEWERVERSIONDETECTED”/>
<UpgradeVersion Minimum=”1.0.0″ IncludeMinimum=”yes” Maximum=”$(var.ProductVersion)” IncludeMaximum=”no” Property=”OLDERVERSIONBEINGUPGRADED”/>
<RemoveExistingProducts After=”InstallInitialize” />
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.