WiX - Prevent downgrades with revision checking

I am looking for a way to prevent downgrading my application. But the "problem" is that I have to check the version number

for example: it should be possible to install 1.0.0.2 when installing 1.0.0.1 - but to install 1.0.0.1 when installing 1.0.0.2 should not be.

I know that Element MajorUpgrade only checks the first three tokens. Maybe someone can give me an idea how to do this? Can I write CustomAction for this? - When yes, how can I check in CustomAction which version should be installed and which version is installed? Where do I need to call CustomAction and how can I show the message and prevent the installation from CustomAction?

+4
source share
2 answers

This is a general requirement. Often used the following pattern:

<Upgrade Id="THE-PRODUCT-GUID"> <UpgradeVersion Property="PREVIOUSVERSIONINSTALLED" Minimum="1.0.0.0" Maximum="$(var.packageVersion)" IncludeMinimum="yes" IncludeMaximum="no" MigrateFeatures="yes" /> IncludeMinimum="yes" IncludeMaximum="yes" /> <UpgradeVersion Property="NEWERVERSIONINSTALLED" Minimum="$(var.packageVersion)" Maximum="99.0.0.0" IncludeMinimum="no" IncludeMaximum="yes" /> </Upgrade> <InstallExecuteSequence> <Custom Action="PreventDowngrading" After="FindRelatedProducts">NEWERVERSIONINSTALLED&lt;&gt;"" AND NOT Installed</Custom> <RemoveExistingProducts After="InstallInitialize">PREVIOUSVERSIONINSTALLED&lt;&gt;""</RemoveExistingProducts> </InstallExecuteSequence> 

PreventDowngrading custom action is essentially an interrupt error:

 <CustomAction Id="PreventDowngrading" Error="Newer version already installed." /> 
+1
source

This tutorial on the WIX website worked for me.

To summarize, you should add the UpgradeVersion tag to the Upgrade tag that should be in your product. Then add a custom action and conditionally schedule it - until FindRelatedProducts and testing if a new version is already installed.

The code might look something like this:

 <Product ...> <Upgrade Id="YOUR-UPGRADE_GUID"> <UpgradeVersion OnlyDetect="yes" Property="NEWERFOUND" Minimum="{CURRENTVERSION}}" IncludeMinimum="no" /> </Upgrade> <CustomAction Id="NoDowngrade" Error="Error Message" /> <InstallExecuteSequence> <Custom Action="NoDowngrade" After="FindRelatedProducts">NEWERFOUND</Custom> <RemoveExistingProducts Before="InstallInitialize" /> </InstallExecuteSequence> </Product> 

Replace CURRENTVERSION with the version number of your product.

+1
source

Source: https://habr.com/ru/post/1410846/


All Articles