简体   繁体   中英

Specify a file id with heat in 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?

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM