Wix 自定义卸载操作 - 如何在 msi 删除文件之前 运行

Wix custom uninstallation action - how to run before msi removing files

我有一个将文件添加到安装目录的自定义操作。卸载程序时,另一个自定义操作会尝试删除这些文件,以便删除安装目录。

问题是我的自定义卸载操作运行s 删除标准安装文件后,所以安装目录留在那里,尽管它是空的。

配置类似于:

<CustomAction Id="AddFilesAction" BinaryKey="installerActions" DllEntry="AddFiles" Execute="deferred" Return="check" Impersonate="no" />
<CustomAction Id="CleanupAction" BinaryKey="installerActions" DllEntry="Cleanup" Execute="deferred" Return="check" Impersonate="no" />

<InstallExecuteSequence>
  <Custom Action="CleanupAction" Before="InstallFiles">Installed</Custom>
  <Custom Action="AddFilesAction" After="InstallFiles">NOT Installed</Custom>
</InstallExecuteSequence>

我可以在 msi 开始删除安装文件之前设置 CleanupAction 运行,以便自定义文件已经删除并且 msi 可以删除主安装目录吗?

The problem is that my custom uninstallation action runs after the removal of standard install files

那是因为您已将其安排在 InstallFiles 之前,后者在 standard InstallExecuteSequence 中排在 RemoveFiles 之后。您还可以在 Orca 或 InstEd 等编辑器中打开 MSI 文件,然后查看 InstallExecuteSequence table。按 Sequence 列排序以查看执行顺序。

Can I make the CleanupAction run before the msi starts removing installation files

当然可以,只需安排在 RemoveFiles:

之前
<Custom Action="CleanupAction" Before="RemoveFiles">
    (REMOVE~="ALL") AND (NOT UPGRADINGPRODUCTCODE)
</Custom>

编辑: 在 Stein Åsmul 让我知道后,我还改进了自定义操作条件。 求详细推理。


如果您还不知道,WiX 已经支持删除应用程序生成的文件,这可能会取代您的自定义操作。它以 RemoveFile and util:RemoveFolderEx 元素的形式出现。

如果这些不能满足您的需求,所以您仍然需要自定义操作,我建议在运行时将要删除的文件的临时记录添加到 RemoveFile table (在 立即 自定义操作中!)。这为您提供了使用 MSI 引擎进行实际文件删除的好处,即。 e.如果用户决定取消卸载或发生错误时自动回滚。我过去这样做过(在发明 RemoveFolderEx 之前),所以如果您需要更多信息,请再问一个问题。

我不会在 InstallInitialize 和 InstallFinalize 之间安排您的操作。在 Initialize 之前放置您的文件,并在 Finalize 之后清理您的文件。请注意,您将在 InstallFinalize 后丢失 属性 值,您需要考虑到这一点。

简答:你的条件和顺序好像不对。请将您的清理自定义操作安排在 RemoveFiles 之前 运行,并可能设置一个更好的条件,以便仅在需要时(不是在意外情况下)使操作 运行设置模式)。下面我建议(REMOVE~="ALL") AND (NOT UPGRADINGPRODUCTCODE)。如果您使用此条件,请彻底测试。 这种情况解释如下

快速示例:

<InstallExecuteSequence>
  <Custom Action="CleanupAction" 
          Before="RemoveFiles">(REMOVE~="ALL") AND (NOT UPGRADINGPRODUCTCODE)</Custom>
</InstallExecuteSequence>

请务必阅读以下详细信息。您可能还想收紧复制文件操作的条件 - 因为它也会 运行 进行重大升级 - 这可能是也可能不是你想要的。


Custom Action Alteratives - summary of some custom action problems - they are serious). Custom actions are the leading cause of deployment failure. Are you sure you need them? Very often there are other ways to achive what you implement in custom actions using built-in MSI features or WiX-specific constructs. Common examples are: installing services, deleting files, updating XML files or INI files, etc... Sometimes custom actions are necessary though - obviously. ,所以我不会在这里重复 - 请检查他/她的回答.


RemoveFiles:这里还有其他问题 - 我将在下面尝试描述这些问题 - 但文件在标准操作时被卸载RemoveFiles 运行秒。换句话说,您需要在 InstallExecuteSequence.

中的此标准操作之前将清理自定义操作安排到 运行

条件:您的清理自定义操作的条件Installed将除了 uninstallmajor upgrade initiated uninstalls 之外,还对 modifyrepairminor upgrade patching 进行自定义操作 运行。这很可能不是您想要的。要仅在卸载时指定 运行,最 运行 的条件是 REMOVE~="ALL"。这将使清理发生在手动启动的卸载和主要升级启动的卸载上(我想这不是你想要的)。您可以尝试 (REMOVE~="ALL") AND (NOT UPGRADINGPRODUCTCODE)(运行 仅适用于常规卸载 - 不适用于主要升级卸载)。


提示: 条件很容易搞砸——即使对于有经验的 WiX / MSI 用户也是如此。一些可能有帮助的资源:

  • Common MSI Conditions Cheat Sheet (from Installshield, hotlink to actual PDF)
  • How to add a WiX custom action that happens only on uninstall (via MSI)?(有用的概述,一些小插曲或难以解释的细节 - 特别是与 REMOVE 属性 有关 - 但总的来说可以作为概述和速成课程)

一些进一步的链接(供参考):