Tuesday, July 20, 2010

Using wix3 and heat to create a wxi through xls transform.

Here is a transform file which can be used with wix3 and heat if you want to create a wix include file (wxi) from a wxs fragment.

Update: Added CompnentGroupRef, CompnentGroup and CompnentRef incase -cg flag is used with heat on a fragment.
<xsl:stylesheet exclude-result-prefixes="wix" version="1.0" xmlns:wix="http://schemas.microsoft.com/wix/2006/wi" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output encoding="UTF-8" indent="yes" method="xml">
  <xsl:strip-space elements="*">
  <xsl:template match="/">
    <include>
      <xsl:apply-templates>
    </xsl:apply-templates></include>
  </xsl:template>


  <xsl:template match="wix:ComponentGroupRef">
    <xsl:element name="{name()}">
      <xsl:copy-of select="@*">
      <xsl:apply-templates>
    </xsl:apply-templates></xsl:copy-of></xsl:element>
  </xsl:template>


  <xsl:template match="wix:ComponentGroup">
    <xsl:element name="{name()}">
      <xsl:copy-of select="@*">
      <xsl:apply-templates>
    </xsl:apply-templates></xsl:copy-of></xsl:element>
  </xsl:template>


  <xsl:template match="wix:ComponentRef">
    <xsl:element name="{name()}">
      <xsl:copy-of select="@*">
      <xsl:apply-templates>
    </xsl:apply-templates></xsl:copy-of></xsl:element>
  </xsl:template>


  <xsl:template match="wix:DirectoryRef">
    <xsl:element name="{name()}">
      <xsl:copy-of select="@*">
      <xsl:apply-templates>
    </xsl:apply-templates></xsl:copy-of></xsl:element>
  </xsl:template>


  <xsl:template match="wix:Directory">
    <xsl:element name="{name()}">
      <xsl:copy-of select="@*">
      <xsl:apply-templates>
    </xsl:apply-templates></xsl:copy-of></xsl:element>
  </xsl:template>


  <xsl:template match="wix:Component">
    <xsl:element name="{name()}">
      <xsl:copy-of select="@*">
      <xsl:apply-templates>
    </xsl:apply-templates></xsl:copy-of></xsl:element>
  </xsl:template>


  <xsl:template match="wix:File">
    <xsl:element name="{name()}">
      <xsl:copy-of select="@*">
      <xsl:apply-templates>
    </xsl:apply-templates></xsl:copy-of></xsl:element>
  </xsl:template>


</xsl:strip-space>
</xsl:output>
</xsl:stylesheet>

If you need other elements it should just to copy the templates for File, Directory, Component or DirectoryRef and and rename the match. 

To use it, use the -t parameter when calling heat.exe
Example: (above saved as transform_fragment_to_inc.xsl)

heat.exe" dir "files\to\harvest" -gg -g1 -nologo -scom -sfrag -srd -sreg -svb6 -template:fragment -t:"transform_fragment_to_inc.xsl" -out "include_file.wxi"

Note: this xsl doesn't support registry entries or registering of com components when harvested by heat.