在Wix中指定带有热量的文件ID

时间:2012-07-20 10:53:50

标签: xml xslt wix

我正在收获一个带有热量的文件,我真的想给它一个不错的id而不是通常的“filXXXXXXXX”,主要是因为我需要在安装程序的其他部分引用它。我知道Id总是相同的,在不同的机器上和不同的文件内容显然所以我可以放心使用它,并且相信它在构建时不会改变,比如说,在CI服务器上。

当然,让这个价值更加人性化会好得多。似乎Heat没有生成文件ID的命令行选项(编辑:显然有一个-suid选项将停止生成数字ID,只使用文件名作为ID,无论如何在许多场景中都不可行) ,所以我正在经历编写XSLT的痛苦,但无法实现我想要的,任何人都可以帮忙吗?

这是片段文件:

<?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>

这是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>

现在,我是一个使用XSL的真正的菜鸟,所以上面的文件可能完全是废话,但无论如何发生的事情是“File”元素被立即复制而不会更改Id。

有什么想法吗?

1 个答案:

答案 0 :(得分:5)

您的基本问题是命名空间或XML根元素wi。 你没有解决这个问题,所以XSLT实际上根本找不到你的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>
相关问题