我正在用 heat 收集一个文件,我真的很想给它一个像样的 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。
有什么想法吗?
最佳答案
您的基本问题是 namespace 或您的 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>
关于xml - 在 Wix 中指定带有 heat 的文件 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11577878/