Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WiX 3.5 Install Service from Heat, Need from Custom Action?

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.

like image 371
Snowy Avatar asked Aug 11 '11 04:08

Snowy


2 Answers

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>
like image 189
Kieron Avatar answered Oct 21 '22 15:10

Kieron


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

like image 34
Bob Arnson Avatar answered Oct 21 '22 14:10

Bob Arnson