如何引用WiX安装程序中其他位置生成的heat.exe中的文件?

如何引用WiX安装程序中其他位置生成的heat.exe中的文件?,wix,windows-installer,installation,Wix,Windows Installer,Installation,我已经使用编写了一个新的安装程序。最佳做法似乎是使用heat.exe应用程序运行构建的应用程序文件,并自动生成包含在安装程序中的引用。这非常好,但我发现,通过使用这种技术,除了将这些文件复制到安装目录之外,您几乎可以阻止这些文件在其他任何方面发挥作用。这是因为我似乎无法“引用”这些文件进行其他操作。例如我希望将其中一个文件作为服务安装,但是ServiceInstall机制似乎不允许您使用从harvest中引用的内容。另外,我的一个文件是一个XML文件,我希望在安装过程中根据用户的输入修改该文件。

我已经使用编写了一个新的安装程序。最佳做法似乎是使用heat.exe应用程序运行构建的应用程序文件,并自动生成包含在安装程序中的引用。这非常好,但我发现,通过使用这种技术,除了将这些文件复制到安装目录之外,您几乎可以阻止这些文件在其他任何方面发挥作用。这是因为我似乎无法“引用”这些文件进行其他操作。例如我希望将其中一个文件作为服务安装,但是ServiceInstall机制似乎不允许您使用从harvest中引用的内容。另外,我的一个文件是一个XML文件,我希望在安装过程中根据用户的输入修改该文件。再一次,我似乎无法引用这个文件来在XmlConfig机制中使用

我已经看到了这一点,但选择的答案实际上并没有提供一个例子。为了启动,WiX编译器不允许您在标识符字段中放置“#”符号,因为正如回复帖子所说,它“不是合法标识符”。如果您在收割时使用普通ID,它会抱怨它们已经存在

下面是我的harvest.wxs文件的一个片段

<!-- Xml file I'd like to modify during install -->
<Component Id="cmp78CF3591818BB6F883096F2C98654BA9" Guid="*">
    <File Id="fil1532F0BC6EDCE81B25489D872A72339A" KeyPath="yes" Source="$(var.MyApplication.TargetDir)\log.config" />
</Component>

<!-- ... -->

<!-- Application I'd like to install as a service -->
<Component Id="cmp84F0EA671F93094E33AE84FA2A03BA2E" Guid="*">
    <File Id="filD4A27A27D20D3D734B279B4F21754836" KeyPath="yes" Source="$(var.MyApplication.TargetDir)\MyService.exe" />
</Component>

对于服务安装,我觉得直观的方式应该是这样的:

<Component Id="cmp84F0EA671F93094E33AE84FA2A03BA2E">
    <File Id="filD4A27A27D20D3D734B279B4F21754836" />
    <ServiceInstall
      Id="MyServiceID"
      Name="MyService"
      Type="ownProcess"
      Start="auto"
      ErrorControl="normal"
      Interactive="no">
    </ServiceInstall>
    <ServiceControl Name="MyService" Id="MyServiceControl" Start="install" Stop="both" Remove="uninstall" Wait="yes"/>
</Component>
<!-- Application I'd like to install as a service -->
<Component Id="cmp84F0EA671F93094E33AE84FA2A03BA2E" Guid="*">
    <File Id="filD4A27A27D20D3D734B279B4F21754836" KeyPath="yes" Source="$(var.MyApplication.TargetDir)\MyService.exe" />
    <ServiceInstall
      Id="MyServiceID"
      Name="MyService"
      Type="ownProcess"
      Start="auto"
      ErrorControl="normal"
      Interactive="no">
    </ServiceInstall>
    <ServiceControl Name="MyService" Id="MyServiceControl" Start="install" Stop="both" Remove="uninstall" Wait="yes"/>
</Component>


但这当然行不通,因为它声称ID是重复的。我想是的,但我怎么能说“你知道harvest中的文件'X'…是的,我想将其作为一项服务安装。”我已经能够让安装正常工作,但我不得不从harvest中筛选MyService.exe并手动添加它。现在,如果每次你真的想对一个特定的文件做一些事情时都是这样,那么我想我可能忘记了使用愚蠢的heat.exe技术,手动输入每个文件。那么,从heat.exe收获中引用文件的语法到底是什么呢?

最简单的答案是:不要使用heat.exe为需要特殊处理的文件(如服务)生成创作。从获取中排除这些文件(必要时使用暂存目录)。

Heat已为您生成组件定义。将
ServiceInstall
元素放入harvest.wxs中的组件中。您的新代码段如下所示:

<Component Id="cmp84F0EA671F93094E33AE84FA2A03BA2E">
    <File Id="filD4A27A27D20D3D734B279B4F21754836" />
    <ServiceInstall
      Id="MyServiceID"
      Name="MyService"
      Type="ownProcess"
      Start="auto"
      ErrorControl="normal"
      Interactive="no">
    </ServiceInstall>
    <ServiceControl Name="MyService" Id="MyServiceControl" Start="install" Stop="both" Remove="uninstall" Wait="yes"/>
</Component>
<!-- Application I'd like to install as a service -->
<Component Id="cmp84F0EA671F93094E33AE84FA2A03BA2E" Guid="*">
    <File Id="filD4A27A27D20D3D734B279B4F21754836" KeyPath="yes" Source="$(var.MyApplication.TargetDir)\MyService.exe" />
    <ServiceInstall
      Id="MyServiceID"
      Name="MyService"
      Type="ownProcess"
      Start="auto"
      ErrorControl="normal"
      Interactive="no">
    </ServiceInstall>
    <ServiceControl Name="MyService" Id="MyServiceControl" Start="install" Stop="both" Remove="uninstall" Wait="yes"/>
</Component>


stackoverflow上的其他答案确实是假的?我明白了。问题是,我们运行heat.exe作为构建的一部分。因此,当添加新的二进制文件时,我们不必更改安装程序。这当然会破坏对harvest.wxs的任何自定义更改:(啊,那么要么使用Bob的答案,要么使用xslt向harvest添加服务配置的这个答案:,还有这个问题的答案: