wixwix3major-upgrade

WiX Installer: getting version of the product being upgraded


During a major upgrade from version X to version Y, I need to have a property/variable stating that version X is being upgraded.

When performing a Major Upgrade of a product with a setup built by WiX Installer, is there a way to get the version number being upgraded?


Solution

  • Assuming you're using a WiX majorupgrade element, when an upgrade is detected the value of the WIX_UPGRADE_DETECTED property is set to the productcode of the product being upgraded. You could pass that into the C++ Win32 API MsiGetProductInfo (.... INSTALLPROPERTY_VERSIONSTRING...) to get the version string. I think there's a DTF equivalent, ProductInstallation class that you construct with that productcode and then get the version. If you didn't use the majorupgrade element there is still a property like PREVIOUSVERSIONSINSTALLED that will get set to the productcode, so it depends on exactly how you've set it up. Note that strictly speaking you could be upgrading more than one product. This would be done after FindRelatedProducts. Anyway, that's what I'd look at.

    I don't think there's a built-in way to get the version. You'd need to know that the upgrade is actually going to work first, so you'd need the property that is set by the FindRelatedProducts upgrade search. There are other things you could do, but I don't know if they would work in your situation. For example if you were launching the MSI from an external program it could enumerate related products to the MSI's productcode, get the version and pass it as a property on the command line to reduce what the MSI would need to do, assuming the upgrade is going to work, but that may be useless in your situation.