首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >WiX:当文件元素由heat.exe生成时,安装并启动服务

WiX:当文件元素由heat.exe生成时,安装并启动服务
EN

Stack Overflow用户
提问于 2011-11-09 22:37:54
回答 2查看 2.4K关注 0票数 3

我有一个WiX安装程序来安装和启动服务。但是,我发现的所有示例都将ServiceInstall标记放在要作为服务安装的.exe文件的文件标记的正下方。我不能这样做,因为我正在使用heat在一个单独的文件中生成文件元素。因此,我的wix脚本如下所示:

代码语言:javascript
复制
 <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,但我想安装的文件除外,尽管所有文件都在它们自己的组件中。我现在有点不知所措:

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-11-10 01:08:02

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

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

票数 2
EN

Stack Overflow用户

发布于 2019-11-06 01:05:19

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

以下是一些需要注意的事情:

  • 服务控制不会在安装时自动启动服务,我遇到了程序集引用在msi尝试调用它们时尚未填充的问题
  • XSLT的一个关键部分在heat.exe文件的顶部添加了一个“

”语句,以便我可以引用.wxi文件中的变量

  • 假设您告诉-var注入的变量名为"var.SourcePath“
  • 我从未将.exe文件或设置文件的名称提取出来作为可以注入到转换中的变量,因为它们相当稳定,而且它非常稳定。

代码语言:javascript
复制
<?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> 
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8066577

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档