首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >wix HeatDirectory ServiceInstall

wix HeatDirectory ServiceInstall
EN

Stack Overflow用户
提问于 2013-11-25 12:54:48
回答 3查看 5.6K关注 0票数 14

我正在使用HeatDirectory创建源文件.wxs。在拾音器目录中,有一个作为服务安装的exe。实际上,如果我自己创建组件,我知道如何安装服务,但我不知道如何在自动生成的组件中包含ServiceInstall。有什么建议吗?

代码语言:javascript
复制
        <HeatDirectory DirectoryRefId="Guardian" OutputFile="Source\GuardianSource.wxs" Transforms="Filter.xsl" Directory="..\Setup\C24.Guardian\bin\Debug" PreprocessorVariable="var.GuardianPath" ComponentGroupName="GuardianGroup" ToolPath="$(WixToolPath)" SuppressCom="true" SuppressFragments="true" SuppressRegistry="true" SuppressRootDirectory="true" AutoGenerateGuids="true" GenerateGuidsNow="false">
    </HeatDirectory>



<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Fragment>
    <DirectoryRef Id="Guardian">
        <Component Id="cmp70BEDA00F3161F3FB5E847EB1136B1D5" Guid="*">
            <File Id="fil26DCBF1E4218C7363018FBA2CD456633" KeyPath="yes" Source="$(var.GuardianPath)\C24.Guardian.exe" />
        </Component>
        <Component Id="cmp2EE8126A193FA022ED35FAD8F182E65A" Guid="*">
            <File Id="fil785CD681C496EDDAB457E8314C49D686" KeyPath="yes" Source="$(var.GuardianPath)\C24.Guardian.exe.config" />
        </Component>
        <Component Id="cmp0CC91B457FBC44F978A2AD6B24043DCF" Guid="*">
            <File Id="fil2D304D0395599AAAAAF975A2DBFD530F" KeyPath="yes" Source="$(var.GuardianPath)\C24.Guardian.pdb" />
        </Component>
        <Component Id="cmpFB799FA015274DDBE2C337C60667D2C5" Guid="*">
            <File Id="filB9C39B394CAD03F5A1BC3262C61EDDEB" KeyPath="yes" Source="$(var.GuardianPath)\C24.Guardian.vshost.exe" />
        </Component>
        <Component Id="cmp28C29865AE85B067BCEEBD70EFDB19D5" Guid="*">
            <File Id="fil0A756B711769AAD657F306B3A6EA7134" KeyPath="yes" Source="$(var.GuardianPath)\C24.Guardian.vshost.exe.config" />
        </Component>
        <Component Id="cmp92A715A4BD4B580A6E70362230170428" Guid="*">
            <File Id="filBD9D504F303A6EEC9E340E3872BBB0AE" KeyPath="yes" Source="$(var.GuardianPath)\C24.Guardian.vshost.exe.manifest" />
        </Component>
        <Component Id="cmp8AB6A241FA2D13F296CBD946C9711579" Guid="*">
            <File Id="fil8EF8CC607CB82B32F84FC9EC2F1636B9" KeyPath="yes" Source="$(var.GuardianPath)\com.Contact24.Tools.dll" />
        </Component>
        <Component Id="cmpC0DBB85C89E8AEA9BAC6E32B85913A2C" Guid="*">
            <File Id="fil917CD649C5C318C6717D8EA9FFDF911A" KeyPath="yes" Source="$(var.GuardianPath)\com.Contact24.Tools.pdb" />
        </Component>
        <Component Id="cmp8AFB0FC7CCF571B61196D9166DEEBA24" Guid="*">
            <File Id="fil32C12DF0163D5BAD7D0495F2CA2C8DA1" KeyPath="yes" Source="$(var.GuardianPath)\ICSharpCode.SharpZipLib.dll" />
        </Component>
        <Component Id="cmpF5DE5EB2B4C6E33F0C32CFF5F464432C" Guid="*">
            <File Id="fil3C8C6F29095A04034E72FBB187F8B841" KeyPath="yes" Source="$(var.GuardianPath)\log4net.dll" />
        </Component>
        <Component Id="cmp27A7791E229DDDBC065069B26138FC2F" Guid="*">
            <File Id="fil8DED592D9F63E708FEF848D2980A5186" KeyPath="yes" Source="$(var.GuardianPath)\log4net.xml" />
        </Component>
    </DirectoryRef>
</Fragment>
<Fragment>
    <ComponentGroup Id="GuardianGroup">
        <ComponentRef Id="cmp70BEDA00F3161F3FB5E847EB1136B1D5" />
        <ComponentRef Id="cmp2EE8126A193FA022ED35FAD8F182E65A" />
        <ComponentRef Id="cmp0CC91B457FBC44F978A2AD6B24043DCF" />
        <ComponentRef Id="cmpFB799FA015274DDBE2C337C60667D2C5" />
        <ComponentRef Id="cmp28C29865AE85B067BCEEBD70EFDB19D5" />
        <ComponentRef Id="cmp92A715A4BD4B580A6E70362230170428" />
        <ComponentRef Id="cmp8AB6A241FA2D13F296CBD946C9711579" />
        <ComponentRef Id="cmpC0DBB85C89E8AEA9BAC6E32B85913A2C" />
        <ComponentRef Id="cmp8AFB0FC7CCF571B61196D9166DEEBA24" />
        <ComponentRef Id="cmpF5DE5EB2B4C6E33F0C32CFF5F464432C" />
        <ComponentRef Id="cmp27A7791E229DDDBC065069B26138FC2F" />
    </ComponentGroup>
</Fragment>
</Wix>

获得如下自动生成的代码是很好的:

代码语言:javascript
复制
        <ComponentRef Id="cmp70BEDA00F3161F3FB5E847EB1136B1D5">
                        <ServiceInstall
                              Id="ServiceAdminGuardianInstaller"
                              Type="ownProcess"
                              Vital="yes"
                              Name="C24.Guardian"
                              DisplayName="C24.Guardian"
                              Description="Служба контроля работы сервера администрирования"
                              Start="auto"
                              Account="[SERVICEACCOUNT]"
                              Password="[SERVICEPASSWORD]"
                              ErrorControl="ignore"
                              Interactive="no">

                            <util:PermissionEx
                                User="Everyone"
                                GenericAll="yes"
                                ServiceChangeConfig="yes"
                                ServiceEnumerateDependents="yes"
                                ChangePermission="yes"
                                ServiceInterrogate="yes"
                                ServicePauseContinue="yes"
                                ServiceQueryConfig="yes"
                                ServiceQueryStatus="yes"
                                ServiceStart="yes"
                                ServiceStop="yes"/>

                        </ServiceInstall>

                        <ServiceControl Id="StopGuardianService" Name="C24.Guardian" Stop="both" Wait="yes" Remove="uninstall" />
       </ComponentRef>
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-11-25 16:07:26

作为@sttaq描述的方法的替代方法,我通常做的是过滤掉.exe文件并手动管理它们。您已经在使用xsl文件(Filter.xsl)过滤您的热输出,因此应该很容易添加一条规则来过滤掉任何*.exe文件。

代码语言:javascript
复制
<!--Match and ignore .exe files-->
<xsl:key name="exe-search" match="wix:Component[contains(wix:File/@Source, '.exe')]" use="@Id"/>
<xsl:template match="wix:Component[key('exe-search', @Id)]"/>
<xsl:template match="wix:ComponentRef[key('exe-search', @Id)]"/>

然后,在.wxs文件中,您可以手动编写.exe文件组件,包括服务安装程序、图标或您可能需要的任何东西。只需记住将其放在正确的目录中:

代码语言:javascript
复制
  <Fragment>
    <DirectoryRef Id="dirA9BC717C5B7BCAAF2B4C1161965AD894">
      <Component Id="ExecFileComponent" Guid="YOUR-GUID-HERE">
        <RemoveFile Id="RemoveLogFiles" Name="*.svclog" On="both"/>
        <File Id="ExecFile" Source="$(exefile)" KeyPath="yes" />
        <ServiceInstall Id="ServiceInstallation" DisplayName="displayname" Name="name" ErrorControl="normal" Start="auto" Type="ownProcess" Vital="yes">
          <util:PermissionEx
            User="Everyone"
            GenericAll="yes"
            ServiceChangeConfig="yes"
            ServiceEnumerateDependents="yes"
            ChangePermission="yes"
            ServiceInterrogate="yes"
            ServicePauseContinue="yes"
            ServiceQueryConfig="yes"
            ServiceQueryStatus="yes"
            ServiceStart="yes"
            ServiceStop="yes" />
        </ServiceInstall>
        <ServiceControl Id="ServiceControl" Name="name" Stop="both" Remove="uninstall" />
      </Component>
    </DirectoryRef>
  </Fragment>
票数 13
EN

Stack Overflow用户

发布于 2013-11-25 13:36:52

我假设您已经知道需要包装在ServiceInstall元素中的文件的名称。

这可以通过使用xsl转换来实现。这个过程可以使用XslTransformation MSBuild任务实现自动化。以下是我最近所做的工作:

wixproj目标中的BeforeBuild文件中,添加一些要传递给xsl的参数,如果您愿意,可以在xsl中对这些参数进行硬编码,并跳过以下步骤:

代码语言:javascript
复制
<PropertyGroup>
  <WixServiceParams>
    <Parameter Name="InstallFolder" Value="INSTALLFOLDER" />
    <!-- INSTALLFOLDER is Guardian in your case -->
    <Parameter Name="DisplayName" Value="Service Display Name" />
    <Parameter Name="Name" Value="ServiceName" />
    <Parameter Name="Description" Value="Service Description." />
  </WixServiceParams>
  <DefineConstants>...</DefineConstants>
</PropertyGroup>

然后,在HeatDirectory任务调用XslTransformation任务之后,如下所示:

代码语言:javascript
复制
<XslTransformation XslInputPath="WixService.xsl" XmlInputPaths="Input.wxs" OutputPaths="Final.wxs" Parameters="$(WixServiceParams)" />

WixService.xsl转换文件添加到项目中。该文件如下:

代码语言:javascript
复制
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:wix="http://schemas.microsoft.com/wix/2006/wi" xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
  <xsl:output omit-xml-declaration="yes" indent="yes"/>

  <xsl:param name="InstallFolder"/>
  <xsl:param name="DisplayName"/>
  <xsl:param name="Name"/>
  <xsl:param name="Description"/>

  <xsl:template match="node()|@*">
    <xsl:copy>
      <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
  </xsl:template>

  <!-- Set Directory Reference to INSTALLFOLDER (set if required) -->
  <xsl:template match="wix:DirectoryRef/@Id">
    <xsl:attribute name="Id">
      <xsl:value-of select="$InstallFolder"/>
    </xsl:attribute>
  </xsl:template>

  <!-- XSL Template to inject WiX service installation elements to a .wxs generated from Heat Project task -->
      <!-- There may be other ways to look for your file -->
  <xsl:template match='wix:Wix/wix:Fragment/wix:DirectoryRef/wix:Component[wix:File[@Source="PATH-TO\YourService.exe"]]'>      
    <xsl:element name="wix:Component">      
      <xsl:attribute name="Id">
        <xsl:value-of select="@Id"/>
      </xsl:attribute>
      <xsl:attribute name="Guid">
        <xsl:value-of select="@Guid"/>
      </xsl:attribute>

      <xsl:element name="wix:File">
        <xsl:attribute name="Id">
          <xsl:value-of select="wix:File/@Id"/>
        </xsl:attribute>
        <xsl:attribute name="Source">
          <xsl:value-of select="wix:File/@Source"/>
        </xsl:attribute>
        <xsl:attribute name="KeyPath">yes</xsl:attribute>
      </xsl:element>

      <xsl:element name="wix:ServiceInstall">
        <!-- Service Install -->
        <xsl:attribute name="Id">SERVICEINSTALLER</xsl:attribute>
        <xsl:attribute name="DisplayName">
          <xsl:value-of select="$DisplayName"/>
        </xsl:attribute>
        <xsl:attribute name="Name">
          <xsl:value-of select="$Name"/>
        </xsl:attribute>
        <xsl:attribute name="Description">
          <xsl:value-of select="$Description"/>
        </xsl:attribute>
        <xsl:attribute name="Start">auto</xsl:attribute>
        <xsl:attribute name="Type">ownProcess</xsl:attribute>
        <xsl:attribute name="Account">[USERNAME]</xsl:attribute>
        <xsl:attribute name="Password">[PASSWORD]</xsl:attribute>
        <xsl:attribute name="ErrorControl">normal</xsl:attribute>
        <xsl:attribute name="Vital">yes</xsl:attribute>
        <!-- Service Dependencies, if required -->
        <xsl:element name="wix:ServiceDependency">
          <xsl:attribute name="Id">DEPENDENCY</xsl:attribute>
        </xsl:element>
        <!-- Service Configuration, set as required -->
        <xsl:element name="util:ServiceConfig">
          <xsl:attribute name="FirstFailureActionType">restart</xsl:attribute>
          <xsl:attribute name="SecondFailureActionType">restart</xsl:attribute>
          <xsl:attribute name="ThirdFailureActionType">none</xsl:attribute>
          <xsl:attribute name="RestartServiceDelayInSeconds">60</xsl:attribute>
        </xsl:element>

      </xsl:element>
      <!-- Service Control, set as required -->
      <xsl:element name="wix:ServiceControl">
        <xsl:attribute name="Id">SERVICECONTROLLER</xsl:attribute>
        <xsl:attribute name="Name">
          <xsl:value-of select="$Name"/>
        </xsl:attribute>
        <xsl:attribute name="Remove">uninstall</xsl:attribute>
        <xsl:attribute name="Stop">uninstall</xsl:attribute>
        <xsl:attribute name="Wait">no</xsl:attribute>
      </xsl:element>

    </xsl:element>       
  </xsl:template>

</xsl:stylesheet>

一旦完成,希望有一个更好的方法来做这件事..。

票数 6
EN

Stack Overflow用户

发布于 2022-12-02 00:37:59

我想出了一个.xsl文件,它可以从<HeatDirectory>生成的文件和组件列表中剪短Windows可执行文件

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
                xmlns:wix="http://schemas.microsoft.com/wix/2006/wi">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />

    <!-- Deep copy everything else that is not the Windows Service .exe file -->
    <xsl:template match="@* | node()">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()" />
        </xsl:copy>
    </xsl:template>

    <!-- Remove the Windows Service .exe file from the list of auto-generated components -->
    <xsl:template match="wix:Component[wix:File/@Source='$(var.PublishDir)\MyWindowsService.exe']"></xsl:template>
    <xsl:template match="wix:ComponentRef[@Id=//wix:Component[wix:File/@Source='$(var.PublishDir)\MyWindowsService.exe']/@Id]">
        <xsl:apply-templates />
    </xsl:template>

</xsl:stylesheet>

var.PublishDir被指定为<HeatDirectory>PreprocessorVariable属性。我还在PublishDir中添加了<DefineConstants>

代码语言:javascript
复制
<PropertyGroup>
  <DefineConstants>BuildVersion=%(AssemblyVersion.Version);PublishDir=$(PublishDir)</DefineConstants>
</PropertyGroup>

<PublishDir>具有指向要发布Windows的文件夹的路径,

代码语言:javascript
复制
<PropertyGroup>
  <PublishDir>$(ProjectDir)Publish</PublishDir>
</PropertyGroup>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20193681

复制
相关文章

相似问题

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