简体   繁体   English

WiX 安装程序:使用 xslt 和 heat.exe 更新属性

[英]WiX Installer: using xslt with heat.exe to update attributes

I am trying to create a WiX installer for a Windows service, and I have read that I need to set the KeyPath to “no” for all my files, with the exception of the .exe in my WiX script.我正在尝试为 Windows 服务创建 WiX 安装程序,并且我读到我需要将所有文件的 KeyPath 设置为“no”,但 WiX 脚本中的 .exe 除外。 I am currently generating my Directory and file structure using Heat.exe here is my command:我目前正在使用 Heat.exe 生成我的目录和文件结构,这是我的命令:

"$(WIX)bin\heat.exe" dir $(SolutionDir)EmailGenerationService\bin\PROD 
                    -cg EmailGenFiles -gg -scom -sreg -sfrag -srd -suid 
                    -dr INSTALLLOCATION -var var.FileSource 
                    -t $(Projectdir)KeyPathTransform.xslt 
                    -out $(ProjectDir)DirectoryAndFileComponents.wxs

It is my intention to update all the file elements with Keypath=”no” in my DirectoryAndFileComponents.wxs file.我打算更新 DirectoryAndFileComponents.wxs 文件中Keypath=”no”所有文件元素。 A sample of the output from heat is:热量输出的示例是:

<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Fragment>
    <DirectoryRef Id="INSTALLLOCATION">
      <Component Id="Dollar.Common.dll" Guid="{2BCD0767-2383-47CF-B1BF-325FA4A3264F}">
        <File Id="Dollar.Common.dll" KeyPath="yes" Source="$(var.FileSource)\Dollar.Common.dll" />
      </Component>
      <Component Id="Dollar.Common.Exceptions.dll" Guid="{B7238091-76D1-42F5-A3B4-A539DFF3BD92}">
        <File Id="Dollar.Common.Exceptions.dll" KeyPath="yes" Source="$(var.FileSource)\Dollar.Common.Exceptions.dll" />
      </Component>
      <Component Id="Dollar.Common.Exceptions.pdb" Guid="{43711979-747D-49C9-BAE4-ECD44FAF5E67}">
        <File Id="Dollar.Common.Exceptions.pdb" KeyPath="yes" Source="$(var.FileSource)\Dollar.Common.Exceptions.pdb" />
      </Component>
      <Component Id="Dollar.Common.Logging.dll" Guid="{59F9ABF3-5F68-410C-BC96-0556282F1E04}">
        <File Id="Dollar.Common.Logging.dll" KeyPath="yes" Source="$(var.FileSource)\Dollar.Common.Logging.dll" />
      </Component>

Here is the XSLT I am passing to heat to perform the transformation:这是我传递给 heat 以执行转换的 XSLT:

<?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/wix"
            xmlns:my="my:my">

  <xsl:output method="xml" indent="no"/>

  <xsl:strip-space elements="*"/>

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

  <xsl:template match='/wix:Wix/wix:Fragment/wix:DirectoryRef/wix:Component/wix:File[@Id and not (@Id="EmailGenerationService.exe")]'>
    <xsl:attribute name="KeyPath">
          <xsl:value-of select="no"/>
    </xsl:attribute>
  </xsl:template>
</xsl:stylesheet>

I have tried quite a few variations of this based on other posts on this site and else where, but as yet have been unable to get the file created by heat.exe to have KeyPath=”no”.我已经根据本网站上的其他帖子和其他地方的其他帖子尝试了很多变体,但到目前为止还无法让 heat.exe 创建的文件具有 KeyPath=”no”。

Am I missing something obvious?我错过了一些明显的东西吗?

You have two different defined namespaces:您有两个不同的定义命名空间:

  1. In XML: http://schemas.microsoft.com/wix/2006/wi在 XML 中: http://schemas.microsoft.com/wix/2006/wi : http://schemas.microsoft.com/wix/2006/wi
  2. In XSLT: http://schemas.microsoft.com/wix/2006/wix在 XSLT 中: http://schemas.microsoft.com/wix/2006/wix : http://schemas.microsoft.com/wix/2006/wix

As far as I know, correct namespace for WiX is http://schemas.microsoft.com/wix/2006/wi .据我所知,WiX 的正确命名空间是http://schemas.microsoft.com/wix/2006/wi So you should change your XSLT.所以你应该改变你的 XSLT。

XSLT: XSLT:

<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"
            xmlns:my="my:my">

    <xsl:output method="xml" indent="yes" />

    <xsl:strip-space elements="*"/>

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

    <xsl:template match='wix:Wix/wix:Fragment/wix:DirectoryRef/wix:Component/wix:File[@Id and not (@Id = "EmailGenerationService.exe")]'>
        <xsl:copy>
            <xsl:apply-templates select="@*"/>
            <xsl:attribute name="KeyPath">
                <xsl:text>no</xsl:text>
            </xsl:attribute>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

Input XML:输入 XML:

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Fragment>
        <DirectoryRef Id="INSTALLLOCATION">
            <Component Id="Dollar.Common.dll" Guid="{2BCD0767-2383-47CF-B1BF-325FA4A3264F}">
                <File Id="Dollar.Common.dll" KeyPath="yes" Source="$(var.FileSource)\Dollar.Common.dll" />
            </Component>
            <Component Id="Dollar.Common.Exceptions.dll" Guid="{B7238091-76D1-42F5-A3B4-A539DFF3BD92}">
                <File Id="Dollar.Common.Exceptions.dll" KeyPath="yes" Source="$(var.FileSource)\Dollar.Common.Exceptions.dll" />
            </Component>
            <Component Id="Dollar.Common.Exceptions.pdb" Guid="{43711979-747D-49C9-BAE4-ECD44FAF5E67}">
                <File Id="Dollar.Common.Exceptions.pdb" KeyPath="yes" Source="$(var.FileSource)\Dollar.Common.Exceptions.pdb" />
            </Component>
            <Component Id="Dollar.Common.Logging.dll" Guid="{59F9ABF3-5F68-410C-BC96-0556282F1E04}">
                <File Id="Dollar.Common.Logging.dll" KeyPath="yes" Source="$(var.FileSource)\Dollar.Common.Logging.dll" />
            </Component>
        </DirectoryRef>
    </Fragment>
</Wix>

Output XML:输出 XML:

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Fragment>
    <DirectoryRef Id="INSTALLLOCATION">
      <Component Id="Dollar.Common.dll" Guid="{2BCD0767-2383-47CF-B1BF-325FA4A3264F}">
        <File Id="Dollar.Common.dll" Source="$(var.FileSource)\Dollar.Common.dll" KeyPath="no" />
      </Component>
      <Component Id="Dollar.Common.Exceptions.dll" Guid="{B7238091-76D1-42F5-A3B4-A539DFF3BD92}">
        <File Id="Dollar.Common.Exceptions.dll" Source="$(var.FileSource)\Dollar.Common.Exceptions.dll" KeyPath="no" />
      </Component>
      <Component Id="Dollar.Common.Exceptions.pdb" Guid="{43711979-747D-49C9-BAE4-ECD44FAF5E67}">
        <File Id="Dollar.Common.Exceptions.pdb" Source="$(var.FileSource)\Dollar.Common.Exceptions.pdb" KeyPath="no" />
      </Component>
      <Component Id="Dollar.Common.Logging.dll" Guid="{59F9ABF3-5F68-410C-BC96-0556282F1E04}">
        <File Id="Dollar.Common.Logging.dll" Source="$(var.FileSource)\Dollar.Common.Logging.dll" KeyPath="no" />
      </Component>
    </DirectoryRef>
  </Fragment>
</Wix>

I won't answer your original question.我不会回答你原来的问题。 :) :)

I have read that I nned to set the keyPath to “no” for all my files, with the exception of the .exe我已经读到我必须将所有文件的 keyPath 设置为“no”,但 .exe 除外

I think you were mislead.我认为你被误导了。 In reality the ServiceInstall table has a column Component_ , and according to MSDN:实际上ServiceInstall 表有一列Component_ ,根据 MSDN:

to install this service using the InstallService table, the KeyPath for this component must be the executable file for the service.要使用 InstallService 表安装此服务,此组件的 KeyPath 必须是该服务的可执行文件。

It doesn't mean the non-exe files in other components should have @KeyPath='no' .这并不意味着其他组件中的非 exe 文件应该有@KeyPath='no' It just says that the EXE file of the service should reside in a separate component and must be the key path of it.它只是说服务的 EXE 文件应该驻留在一个单独的组件中,并且必须是它的关键路径。

The key path is a very important concept of the MSI technology.关键路径是MSI技术的一个非常重要的概念。 You can read more about it here, see the description of the KeyPath column .您可以在此处阅读有关它的更多信息,请参阅 KeyPath 列的说明

Now, if we get back to your original question - no, you don't have to tweak the heat output the way you mentioned.现在,如果我们回到您最初的问题 - 不,您不必按照您提到的方式调整热量输出。 It will generate the WiX authoring you need by default.默认情况下,它将生成您需要的 WiX 创作。

May I suggest a different approach?我可以建议一种不同的方法吗?

<xsl:template match="@KeyPath[parent::wix:File[parent::wix:Component[parent::wix:DirectoryRef[parent::wix:Fragment[parent::wix:Wix]]]] and . != 'EmailGenerationService.exe']">
        <xsl:attribute name="KeyPath">
            <xsl:value-of select="'no'"/>
        </xsl:attribute>
</xsl:template>

Just change your template matching to the above and you should have the correct result.只需将您的模板匹配更改为上述内容,您就会得到正确的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM