WiX - Prevent downgrade with check for revision

六月ゝ 毕业季﹏ 提交于 2019-12-10 13:42:37

问题


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?


回答1:


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." />



回答2:


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.



来源:https://stackoverflow.com/questions/10461840/wix-prevent-downgrade-with-check-for-revision

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!