【发布时间】:2011-11-25 18:35:52
【问题描述】:
我有一个 util:RemoveFolderEx 元素,我只想在卸载程序时运行它。我把它放在它自己的组件中,然后在属性上设置一个条件来判断它是否应该被包含。
谁能向我解释为什么以下方法不起作用?
<Property Id='UNINSTALLMODE' Value="FALSE"></Property>
<DirectoryRef Id="DATADIR">
<Component Id="C.RemoveDataFolder" Guid="myguid" KeyPath="yes">
<util:RemoveFolderEx On="uninstall" Property="DATADIR" ></util:RemoveFolderEx>
<Condition>(UNINSTALLMODE="TRUE")</Condition>
</Component>
</DirectoryRef>
<CustomAction Id="CA.SetUninstallMode" Property="UNINSTALLMODE" Value="TRUE" />
<InstallExecuteSequence>
<Custom Action="CA.SetUninstallMode" Before="WixRemoveFoldersEx" >(NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL")</Custom>
</InstallExecuteSequence>
我检查了日志,并且在卸载软件时自定义操作正确地将 UNINSTALLMODE 设置为“TRUE”。在安装和重新安装时它是“FALSE”。我已尝试在与 RemoveFoldersEx 相关的 Before="WixRemoveFoldersEx" 和 Before="CostInitialise" 之前安排自定义操作。
非常感谢任何帮助,这让我发疯了!尼尔
编辑:我将 wix 更新为此
<Property Id='P.INSTALLMODE' Value='0'></Property>
<Property Id='P.UNINSTALLMODE' Value='0'></Property>
<DirectoryRef Id="DATADIR">
<Component Id="C.RemoveDataFolder" Guid="myguid" KeyPath="yes">
<util:RemoveFolderEx On="uninstall" Property="DATADIR" ></util:RemoveFolderEx>
<Condition>(P.INSTALLMODE = 1) OR (P.UNINSTALLMODE = 1)</Condition>
</Component>
</DirectoryRef>
<CustomAction Id="CA.SetInstallModeToTrue" Property="P.INSTALLMODE" Value='1' />
<CustomAction Id="CA.SetUninstallModeToTrue" Property="P.UNINSTALLMODE" Value='1' />
<InstallExecuteSequence>
<RemoveExistingProducts Before="InstallInitialize" />
<Custom Action="CA.SetInstallModeToTrue" Before="ValidateProductID" >(NOT UPGRADINGPRODUCTCODE) AND (NOT PREVIOUSVERSIONSINSTALLED)</Custom>
<Custom Action="CA.SetUninstallModeToTrue" Before="ValidateProductID" >(NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL")</Custom>
</InstallExecuteSequence>
自定义操作在从注册表中读取 DATADIR 值之后并在 CostInitialize 之前立即运行。
这是在以下情况下会发生的情况
- 安装 -> 满足条件并安装组件
- 重新安装 -> 条件不满足但组件仍被卸载然后重新安装
- 卸载 -> 满足条件并卸载组件
我能从中得到的只是,该条件仅适用于安装过程,一旦安装了组件,就无法对其施加移除条件。
EDIT2:最后通过使用由自定义操作设置的 removefolderex 属性来实现此功能。现在看起来很简单。
<Property Id='P.REMOVEDATAFOLDER' Secure='yes' />
<DirectoryRef Id="DATADIR">
<Component Id="C.RemoveDataFolder" Guid="myguid" KeyPath="yes">
<util:RemoveFolderEx On="uninstall" Property="P.REMOVEDATAFOLDER" />
</Component>
</DirectoryRef>
<CustomAction Id="CA.SetDataFolder" Property="P.REMOVEDATAFOLDER" Value='[DATADIR]' />
<InstallExecuteSequence>
<Custom Action="CA.SetDataFolder" Before="ValidateProductID" >(NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL")</Custom>
</InstallExecuteSequence>
【问题讨论】:
标签: wix windows-installer