1

我实现 wix 来生成一些 msi。我想维护 .bat 文件(打包在这个 wix 项目中)以包含一些要做的工作(并通过一些自定义操作激活)我在 VS2010 中将 .bet 添加到我的 wix 项目中。

我的问题是

  1. 我如何将它实际包装在目标机器上可以运行脚本的 msi 中?
  2. 我如何在自定义部分元素中实际引用该嵌入式批处理文件
4

2 回答 2

9

这可能不是您正在寻找的答案,但我强烈建议您不要这样做。从 MSI 包中运行批处理文件有许多缺点,总有一天会打你:

  • 防病毒软件可能会阻止执行
  • 至于任何延迟的自定义操作(更改目标系统状态的操作),您必须创建一个回滚操作,而对于可能包含许多不同性质的步骤的批处理文件,它可能要困难得多
  • 你没有进展(我怀疑这对于批处理脚本来说是完全可能的)

相反,我鼓励您执行以下操作:

  • 分析您的批处理脚本并列出它对目标系统所做的确切操作
  • 查看标准的 Windows Installer 功能和 WiX 扩展,了解开箱即用的功能
  • 设计您的安装以尽可能多地使用标准功能并尽可能少地使用自定义操作
  • 如果您仍需要自定义操作,请坚持使用 DLL 操作并确保为延迟操作提供回滚操作
于 2013-06-18T08:03:44.643 回答
3

您正在寻找我认为是类型 18 的自定义操作

The executable is generated from a file installed with the application. The 
Source field of the CustomAction table contains a key to the File table. The 
location of the custom action code is determined by the resolution of the target 
path for this file; therefore this custom action must be called after the file 
has been installed and before it is removed.

CustomAction 元素具有 ExeCommand 属性,仅适用于这种情况。它看起来像这样:

<CustomAction Id="ExecuteMyBatchFile" 
              FileKey="[#FileKey]" 
              ExeCommand="Arguments passed to batch file"
              Execute="deferred"/>

当然,这是假设批处理文件是由 msi 安装的。

于 2013-06-17T22:43:07.903 回答