Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Wix Variables in the XSL Transfomration

Tags:

xslt

wix

heat

I'm harvesting my project files using Heat. but since I want to have shortcuts on the target system the main executable must be ignored by Heat and added manually in the main wxs file. I'm using the following xsl file to tell heat to ignore my executable file (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>

The problem is that I don't want to write the filename directly here, instead I want to set the executable filename as an argument (maybe a wix variable) in my msbuild file. I would be very thankful if anyone could tell me how it is possible. And what other approaches can I take to solve this problem.

like image 920
Hossein Shahdoost Avatar asked Oct 31 '22 16:10

Hossein Shahdoost


1 Answers

After some research, I came up with this solution which loads the Application Name from my msbuild file.

<?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>

I also took a look at the Heat source code to see if it supports xslt param input but it doesn't seem to support the feature yet.

PS: Back there on Heat I saw some real ugly coding. I hope they consider refactoring the source.

like image 196
Hossein Shahdoost Avatar answered Dec 09 '22 23:12

Hossein Shahdoost