I am searching a way to prevent a downgrade of my application. But the "problem" is, that I have to check the revision-number
for example: it should be possible to install 1.0.0.2 when 1.0.0.1 is installed - but it should not be possible to install 1.0.0.1 when 1.0.0.2 is installed.
I know, that the Element MajorUpgrade only check the first three tokens. Perhaps someone can give me an idea, how to do this? Can I wrote a CustomAction to do this? - When yes, how can I check in the CustomAction which version should be installed and which version is installed? Where does I have to call the CustomAction and how can I show a message and prevent installing from the CustomAction?
This is a common requirement. The following pattern frequently used:
<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<>"" AND NOT Installed</Custom>
<RemoveExistingProducts After="InstallInitialize">PREVIOUSVERSIONINSTALLED<>""</RemoveExistingProducts>
</InstallExecuteSequence>
PreventDowngrading
custom action is essentially a breaking error:
<CustomAction Id="PreventDowngrading" Error="Newer version already installed." />
This tutorial on WIX website worked for me.
Summarizing it you have to add UpgradeVersion tag in Upgrade tag which should be in your Product. Then add a custom action and conditionally schedule it - before FindRelatedProducts and testing if a newer version is already installed.
The code could be something like:
<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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With