Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify a file id with heat in Wix

Tags:

xml

xslt

wix

I am harvesting a file with heat and I would really like to give it a decent id rather than the usual "filXXXXXXXX", mostly because I need to refer to it in other parts of the installer. I know that the Id is always the same, on different machines and for different file content apparently so I can stll use it with the confidence that it won't change when builnding, let's say, on a CI server.

Of course it would be much better to have this value a bit more human-friendly. It seems Heat does not have a command-line option to generate file ids (EDIT: apparently there is a -suid option that will stop generating numerical IDs and just use the filename as the ID, anyway that's not feasible in a lot of scenarios), so I am going through the pain of writing an XSLT, but cannot achieve what I want, can anyone help?

This is the Fragment file:

<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Fragment>
        <DirectoryRef Id="DBScripts" />
    </Fragment>
    <Fragment>
        <ComponentGroup Id="CSInstallerConfig">
            <Component Id="cmpD6BAFC85C2660BE8744033953284AB03" Directory="DBScripts" Guid="{A39BABF5-2BAC-46EE-AE01-3B47D6C1C321}">
                <File Id="filB31AC19B3A3E65393FF9059147CDAF60" KeyPath="yes" Source="$(var.CONFIG_PATH)\CSInstaller.config" />
            </Component>
        </ComponentGroup>
    </Fragment>
</Wix>

And this is the XSLT:

<?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">
    <xsl:output method="xml" indent="yes"/>
    <xsl:template match="@*|*">
        <xsl:copy>
            <xsl:apply-templates select="@*|*" />
        </xsl:copy>
    </xsl:template>
    <xsl:template match="File">
        <xsl:attribute name="Id">
            <xsl:value-of select="123"/>
        </xsl:attribute>
    </xsl:template>
</xsl:stylesheet>

Now, I'm a real noob with XSL so maybe the file above is total nonsense, but anyway what's happening is that the "File" element is copied straight away without the Id being changed.

Any idea?

like image 296
Tallmaris Avatar asked Jul 20 '12 10:07

Tallmaris


People also ask

How do I use heat exe on WiX?

Navigate to WiX's bin directory from a command prompt and type heat.exe -? to see information about its usage. To make things easy, consider adding the path to the WiX bin directory to your computer's PATH environment variable so that you won't have to reference the full path to the executable each time you use it.

What are WiX fragments?

The Fragment element is the building block of creating an installer database in WiX. Once defined, the Fragment becomes an immutable, atomic unit which can either be completely included or excluded from a product.

What is candle exe?

The Windows Installer XML compiler is exposed by candle.exe. Candle is responsible for preprocessing the input . wxs files into valid well-formed XML documents against the WiX schema, wix.


1 Answers

Your basic issue is with the namespace or your XML root element wi. You don't address that, so XSLT actually don't find your File element at all.

Next, you'll have to do a little tweak on the templates to correctly copy over the other attributes of File:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:wi="http://schemas.microsoft.com/wix/2006/wi">
    <xsl:output method="xml" indent="yes"/>
    <xsl:template match="@*|*">
        <xsl:copy>
            <xsl:apply-templates select="@*|*" />
        </xsl:copy>
    </xsl:template>
    <xsl:template match="wi:File">
        <xsl:copy>
            <xsl:attribute name="Id">
                <xsl:value-of select="123"/>
            </xsl:attribute>
            <xsl:apply-templates select="@*[not(name()='Id')]" />
            <xsl:apply-templates select="*" />
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>
like image 179
BxlSofty Avatar answered Oct 20 '22 11:10

BxlSofty