WiX 安装程序:使用 xslt 和热量.exe找到父/子匹配后如何更改父 ID 的值?



>我有以下来源:

<DirectoryRef Id="INSTALLDIR">
<Component Id="acuthin.exe" Guid="{0DAD4D00-A40E-420D-B90A-B23B89B72881}">

我想将 INSTALLDIR 更改为 TARGETDIR:

<DirectoryRef Id="TARGETDIR">
<Component Id="acuthin.exe" Guid="{0DAD4D00-A40E-420D-B90A-B23B89B72881}">

但前提是组件 Id="acuthin.exe"。 我尝试了以下方法:

<xsl:template match="wix:DirectoryRef[@Id='INSTALLDIR']/wix:Component[@Id='acuthin.exe']">
<xsl:copy>
<xsl:attribute name="Id">TARGETDIR</xsl:attribute>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>

但它更改了组件的 ID 而不是目录引用:

<DirectoryRef Id="INSTALLDIR">
<Component Id="TARGETDIR">

有没有办法告诉它修改目录引用 ID?

这是我的热命令行:

heat" dir "Files\Groupacuthin.exeAutoUpdate" -dr INSTALLDIR -var var.HARVESTDIR -gg -sw -nologo -scom -sreg -sfrag -srd -suid -cg "Groupacuthin.exeAutoUpdate" -t test.xslt -out "Components\Groupacuthin.exeAutoUpdate.wxs">

这是进行模板匹配之前的源:

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Fragment>
<DirectoryRef Id="INSTALLDIR">
<Component Id="acuthin.exe" Guid="{F48C7EB0-6192-4F92-8FCB-8DC8517572B5}">
<File Id="acuthin.exe" KeyPath="yes" Source="$(var.HARVESTDIR)acuthin.exe" />
</Component>
</DirectoryRef>
</Fragment>
<Fragment>
<ComponentGroup Id="Groupacuthin.exeAutoUpdate">
<ComponentRef Id="acuthin.exe" />
</ComponentGroup>
</Fragment>
</Wix>

谢谢!

加里

您要修改的是 DirectoryRef 的Id 属性,但您的模板实际上是在选择作为 DirectoryRef 子项的组件。

将模板更改为:

<xsl:template match="wix:DirectoryRef[@Id='INSTALLDIR' and wix:Component/@Id='acuthin.exe']">
<xsl:copy>
<xsl:attribute name="Id">TARGETDIR</xsl:attribute>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>

在这里看到它的工作:https://xsltfiddle.liberty-development.net/pPJ8LVx

请尝试以下代码:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="DirectoryRef">
<DirectoryRef>
<xsl:apply-templates select="@* except @Id"/>
<xsl:if test="(@Id='INSTALLDIR') and /Wix/Fragment/ComponentGroup/ComponentRef[@Id='acuthin.exe']">
<xsl:attribute name="Id" select="'TARGETDIR'"/>
</xsl:if>
<xsl:apply-templates/>
</DirectoryRef>
</xsl:template>

Your @match="wix:DirectoryRef[@Id='INSTALLDIR']/wix:Component[@Id='acuthin.exe']" 而不是使用 @match="wix:DirectoryRef[@Id='INSTALLDIR' and wix:Component/@Id='acuthin.exe']">

相关内容

最新更新