这是一个常见的要求。以下模式经常使用:
<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
自定义操作本质上是一个破坏性错误:
<CustomAction Id="PreventDowngrading" Error="Newer version already installed." />