8

I have a VS2010 WiX project with a main .wxs file and an empty .wxs file. The empty .wxs is overwritten in the prebuild event of the project, using heat.exe to harvest everything from a console exe. The exe has InstallUtil hooks, and in the days of VS setup project the exe was installed as a Service.

I tried to use the <ServiceInstall> bits in WiX, but when I specified the executable and other elements to get the Service installed, light complained of a collision between the .exe in the main .wxs and the .exe in the heat-generated .wxs.

I think Custom Action is not the best way to do the service installation, so I am attempting XSL transformation to get the file out that I don't want (it's a single file out of 100).

My XSL must have a problem, because it is not matching/filtering. Here it is:

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

<xsl:template match="
        Component[File/@Source='$(var.bindir)\servicehost.exe']"/
</xsl:stylesheet>

The parts of the .wxs I need to rip out look like this:

    ....
     <Component Id="cmpD64BE1790BFAF0F05DA37558F5D72572" Guid="{6C70DDC8-349B-4B66-A415-DE08E302C2A8}">
                    <File Id="fil24DFDFCA765C9A8BBB8854CE66AED0E8" KeyPath="yes" Source="$(var.bindir)\servicehost.exe" />
                </Component>
    ....
<ComponentRef Id="cmpD64BE1790BFAF0F05DA37558F5D72572" />
    ....

What is the best way to make this work?

Thanks.

Snowy
  • 5,942
  • 19
  • 65
  • 119

2 Answers2

10

The Wix XML elements are in a namespace, so you need to specify the namespace in the match value.

I solved the same problem by using XSL to add in the ServiceInstall and ServiceControl elements to the fragment generated by heat:

<!-- Add the service install/control entries to mybinary.exe -->
<xsl:template match="wix:Component[contains(wix:File/@Source,'mybinary.exe')]">
    <xsl:copy>
        <xsl:apply-templates select="node() | @*" />
        <wix:ServiceInstall Id="MyServiceInstall" DisplayName="[SERVICE_NAME]" Description="[SERVICE_DESC]" Name="MyService" Arguments="" ErrorControl="normal" Start="auto" Type="ownProcess" Vital="yes" Account="LocalSystem" />
        <wix:ServiceControl Id="MyServiceControl" Name="MyService" Start="install" Stop="uninstall" Remove="uninstall" />
    </xsl:copy>
</xsl:template>
Kieron
  • 11,588
  • 5
  • 34
  • 29
  • 1
    To match the binary exactly (in case you have a app.config with the same name), try this match line: – Mo0gles Jul 27 '12 at 06:28
3

Create a staging directory for the files you want to harvest with Heat. Keep the service .exe separate so you can manually author ServiceInstall.

Bob Arnson
  • 21,377
  • 2
  • 40
  • 47
  • Heat is looking at the Service output bin\debug dir. I wish there was a way to exclude a filepattern from Heat. Hmm. Maybe there is a way to use XSL to remove the exe file so I can keep it in my main wxs? – Snowy Aug 11 '11 at 14:35
  • 1
    That's why I suggested creating a staging directory, so you have control over what Heat is harvesting, without needing to go the XSL route. – Bob Arnson Aug 11 '11 at 15:45
  • @dani-carbonell provided a [similar answer](http://stackoverflow.com/a/20197647/1811525) - avoiding a complex transformation and a staging directory at the same time. – CodeFox Jul 28 '14 at 10:02