Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WiX - Prevent downgrade with check for revision

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?

like image 295
BennoDual Avatar asked May 05 '12 12:05

BennoDual


2 Answers

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&lt;&gt;"" AND NOT Installed</Custom>
  <RemoveExistingProducts After="InstallInitialize">PREVIOUSVERSIONINSTALLED&lt;&gt;""</RemoveExistingProducts>
</InstallExecuteSequence>

PreventDowngrading custom action is essentially a breaking error:

<CustomAction Id="PreventDowngrading" Error="Newer version already installed." />
like image 129
KMoraz Avatar answered Nov 11 '22 07:11

KMoraz


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.

like image 20
Syed Ali Avatar answered Nov 11 '22 09:11

Syed Ali