提示在WiX中卸载旧版本的APP

时间:2013-07-31 16:28:27

标签: wix wix3.6

我使用Wix 3.6开发了一个安装程序,可以成功安装应用程序的所有元素。

现在,每次我给msi版本更高版本时,我都希望安装程序提示用户将其卸载。从现在开始我尝试过这个:

<Product 
Id="*" 
Name="!(loc.ProductName)" 
Language="3082" 
Codepage="1252"
Version="1.0.1"
Manufacturer="$(var.ProductManufacturer)" 
UpgradeCode="$(var.UpgradeCode)">

<Property Id="PREVIOUSVERSIONINSTALLED" Secure="yes" />
<Upgrade Id="$(var.UpgradeCode)">
  <UpgradeVersion Minimum="1.0.0.0" Maximum="99.9.9.9" IncludeMiminum="yes" IncludeMaximum="no" Property="PREVIOUSVERSIONSINSTALLED" />
</Upgrade>

<InstallExecuteSequence>
  <RemoveExistingProducts Before="InstallInitialize" />
</InstallExecuteSequence>

此代码成功卸载了计算机上以前安装的所有版本。但是它不会询问用户是否肯定会这样做。

我需要的是Wix安装程序,以提示用户说出如下消息:

  

安装了[ProductName]的早期版本。你想卸载吗? [是的|没有选择。

有没有办法提示用户并检查他是否真的要卸载任何以前的版本?

2 个答案:

答案 0 :(得分:2)

Windows Installer升级表有一个名为msidbUpgradeAttributesOnlyDetect的属性位,由WiX的UpgradeVersion @ OnlyDetect属性表示。

正确创作后,这会导致FindRelatedProducts使用检测到的产品的ProductCode GUID设置您选择的操作属性。虽然它没有将其传递给RemoveExistingProducts进行自动删除。

虽然不是典型的行为,但是没有什么可以阻止您编写一些在此属性具有值时触发的UI。您可以询问用户是否要删除旧版本,如果是,请设置另一个操作属性以告知RemoveExistingProducts。 (提示:作者升级,永远不会找到自己的产品并劫持它的属性以注入删除。)

如果用户拒绝,您可以选择中止安装或将安装并排继续使用其他目录结构。 (Office,Visual Studio等)。

答案 1 :(得分:2)

我在解决同样的问题时发现this post很有用。您可以使用在 upgrade -tag中设置的 PREVIOUSVERSIONINSTALLED 属性来打开自定义对话框。通过添加以下代码(使用标准欢迎对话框时)在一些UI标记内执行此操作:

<Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="OldVersionDlg">PREVIOUSVERSIONSINSTALLED</Publish>
<Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="SetupTypeDlg">NOT Installed AND NOT PREVIOUSVERSIONSINSTALLED</Publish>

我在this Wix tutorial上创建了自己的自定义对话框,最后得到了以下代码:

 <Dialog Id="OldVersionDlg" Width="260" Height="85" Title="[ProductName] Setup" NoMinimize="yes">
        <Control Id="No" Type="PushButton" X="132" Y="57" Width="56" Height="17"
          Default="yes" Cancel="yes" Text="No">
          <Publish Event="EndDialog" Value="Exit">1</Publish>
        </Control>
        <Control Id="Yes" Type="PushButton" X="72" Y="57" Width="56" Height="17" Text="Yes">
          <Publish Event="EndDialog" Value="Return">1</Publish>
        </Control>
        <Control Id="Text" Type="Text" X="48" Y="15" Width="194" Height="30">
          <Text>A previous version of [ProductName] is currently installed. By continuing the installation this version will be uninstalled. Do you want to continue?</Text>
        </Control>
</Dialog>
相关问题