WiX:在heat.exe生成文件元素时安装和启动服务

问题描述 投票:3回答:2

我有一个WiX安装程序来安装和启动服务。但是,我发现的所有示例都将ServiceInstall标记直接放在要作为服务安装的.exe文件的文件标记下方。我无法执行此操作,因为我正在用热量在单独的文件中生成文件元素。所以我的wix脚本看起来像这样:

 <Directory Id="INSTALLLOCATION" Name="Email Generation Service">
        <Component Id="SetupService" Guid="51E78696-80E0-4CDA-8F49-902C67CB129C">
          <CreateFolder  />
          <ServiceInstall Id="ServiceInstaller"
                          Type="ownProcess"
                          Vital="yes"
                          Name="EmailGenerationService"
                          DisplayName="Email Generation Service"
                          Description="Service for generating Emails from Nexus"
                          Start="auto"
                          Account="LocalService"
                          ErrorControl="ignore"
                          Interactive="no">
          </ServiceInstall>
          <ServiceControl Id="StartService" Start="install" Stop="both" Remove="uninstall" Name="EmailGenerationService" Wait="yes" />
        </Component>
 </Directory>

如何告诉WiX我想将哪个文件安装为服务?

我使用XSLT将所有文件上的KeyPath设置为no,但我要安装的文件除外,尽管事实上所有文件都在其自己的组件中。我现在有点茫然:(

wix
2个回答
2
投票

服务必须链接到特定文件。这是Windows Installer的限制。因此,您需要在EXE文件元素下创建ServiceInstall元素。

一种解决方案是对EXE文件进行硬编码,而不是让它自动生成。


0
投票

将其作为相关信息添加,我遇到了类似的问题,并向您使用了类似的解决方案,并添加了xml转换。但是,我使用了转换将服务控制/安装元素插入到热生成的片段中。我在下面粘贴了转换,您可能需要修改属性或删除不需要的项目。

一些注意事项:

  • 服务控件未在安装时自动启动服务,在msi尝试调用程序集引用时未填充程序集引用的问题
  • XSLT的关键部分添加heat.exe文件顶部的“ include”语句,以便我可以我的.wxi文件中的参考变量
  • 假定变量名您告诉热注入,因为-var参数是“ var.SourcePath”
  • 我从没有将.exe文件或设置文件的名称提取为可以注入到转换中的变量,因为它们是相当稳定,似乎...很难
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  xmlns:wix="http://schemas.microsoft.com/wix/2006/wi" 
  xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

  <!-- Template for the new ServiceInstall element -->
  <xsl:param name="pServiceInstall">
    <xsl:element name="ServiceInstall">
      <xsl:attribute name="Id">SVINSTL_$(var.ServiceName)</xsl:attribute>
      <xsl:attribute name="Description">$(var.ServiceInstallDescription)</xsl:attribute>
      <xsl:attribute name="Account">$(var.SystemAccount)</xsl:attribute>
      <xsl:attribute name="DisplayName">$(var.ServiceInstallDisplayName)</xsl:attribute>
      <xsl:attribute name="ErrorControl">normal</xsl:attribute>
      <xsl:attribute name="Name">$(var.ServiceName)</xsl:attribute>
      <xsl:attribute name="Interactive">no</xsl:attribute>
      <xsl:attribute name="Start">auto</xsl:attribute>
      <xsl:attribute name="Type">ownProcess</xsl:attribute>
      <xsl:attribute name="Vital">yes</xsl:attribute>
    </xsl:element>
  </xsl:param>

  <!-- Template for the new ServiceControl element -->
  <xsl:param name="pServiceControl">
    <xsl:element name="ServiceControl">
      <xsl:attribute name="Id">SVCTRL_$(var.ServiceName)</xsl:attribute>
      <xsl:attribute name="Name">$(var.ServiceName)</xsl:attribute>
      <xsl:attribute name="Stop">both</xsl:attribute>
      <xsl:attribute name="Remove">uninstall</xsl:attribute>
      <xsl:attribute name="Wait">yes</xsl:attribute>
    </xsl:element>
  </xsl:param>

  <!-- Insert a ?include statement at the top of the fragment so it can use config variables -->
  <xsl:template match="wix:Wix">
    <xsl:copy>
      <xsl:processing-instruction name="include">InstallerSettings.wxi</xsl:processing-instruction>
      <xsl:apply-templates/>
    </xsl:copy>
  </xsl:template>

  <!-- Turn the file name of the executable into a variable so it can be targeted for shortcuts,etc -->
  <xsl:template match="@Source[. ='$(var.SourcePath)\HARD_CODED_NAME_OF_PROJECT.exe']">
    <xsl:call-template name="identity" />
    <xsl:attribute name="Id">$(var.ServiceExecutableFileId)</xsl:attribute>
  </xsl:template>

  <!-- Insert the ServiceInstall and ServiceControl elements into the component with the exe file -->
  <xsl:template match="//wix:File[@Source='$(var.SourcePath)\HARD_CODED_NAME_OF_PROJECT.exe']">
    <xsl:call-template name="identity" />
    <xsl:copy-of select="$pServiceInstall"/>
    <xsl:copy-of select="$pServiceControl"/>
  </xsl:template>

  <!-- Identity template (copies everything as is) -->
  <xsl:template match="@*|node()" name="identity">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()" />
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet> 
© www.soinside.com 2019 - 2024. All rights reserved.