在XSL Transfomration中使用Wix变量

时间:2015-10-29 13:43:51

标签: xslt wix heat

我使用加热收获我的项目文件。但由于我希望在目标系统上有快捷方式,主要的可执行文件必须被加热忽略,并在主要wxs 文件中手动添加。 我使用以下xsl文件告诉热量忽略我的可执行文件(Aparati.exe)

<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:wix="http://schemas.microsoft.com/wix/2006/wi">
  <!-- strip out the exe files from the fragment heat generates. -->
  <xsl:template match="@*|*">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()" />
    </xsl:copy>
  </xsl:template>
  <xsl:output method="xml" indent="yes" />
  <xsl:key name="exe-search" match="wix:Component[contains(wix:File/@Source, 'Aparati.exe')]" use="@Id" />
  <xsl:template match="wix:Component[key('exe-search', @Id)]" />
  <xsl:template match="wix:ComponentRef[key('exe-search', @Id)]" />
</xsl:stylesheet>

问题是我不想直接在这里写文件名,而是想在我的msbuild文件中将可执行文件名设置为参数(可能是一个wix变量)。如果有人能告诉我它是如何可能的,我将非常感激。我可以采取哪些其他方法来解决这个问题。

1 个答案:

答案 0 :(得分:2)

经过一番研究,我想出了这个从我的msbuild文件加载应用程序名称的解决方案。

<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:wix="http://schemas.microsoft.com/wix/2006/wi"
        xmlns:msbuild="http://schemas.microsoft.com/developer/msbuild/2003">
  <!-- strip out the exe files from the fragment heat generates. -->

  <xsl:output method="xml" indent="yes" />
  <!-- take the app name from msbuild file -->
  <xsl:param name="appName" select="document('..\build.proj')//msbuild:AppName/text()"/>
  <xsl:param name="exeName" select="concat($appName, '.exe')" />

  <!-- copy all the elements -->
  <xsl:template match="@*|*">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()" />
    </xsl:copy>
  </xsl:template>
  <!-- except for Component and ComponentRef elements which contain the $exeName -->
  <xsl:template match="wix:Component|wix:ComponentRef">
    <xsl:choose>
      <xsl:when test="contains(wix:File/@Source, $exeName)"></xsl:when>
      <xsl:otherwise>
        <xsl:copy>
          <xsl:apply-templates select="@*|node()" />
        </xsl:copy>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
</xsl:stylesheet>

我还看了一下热源代码,看它是否支持xslt param输入,但它似乎还不支持这个功能。

PS:回到热火上我看到了一些真正难看的编码。我希望他们考虑重构源代码。