收集用于 PerUser 安装程序的文件

Ili*_*irB 5 xml xslt wix xslt-1.0

我有一个需要明确成为 PerUser msi 的安装程序。当前的问题是,使用 Heat 收集文件并没有提供一种生成完全符合 PerUser 包的组件的方法。尤其ICE64 "The directory dir7956CF617C38D877C93B5A7D33313596 is in the user profile but is not listed in the RemoveFile table.

现在只要我知道结构就不是问题,因为我可以创建一个包含所有目录的组件并将其包含在功能中。但是,如果结构发生变化,那么找出所有目录并手动添加它们是一项手动工作。这消除了其他开发人员自由添加/删除文件的灵活性。

对于那些感兴趣的人来说,我使用的 heat 命令是: heat.exe dir "SourceDir" -dr INSTALLDIR -cg CG_Binaries -nologo -gg -g1 -sfrag -srd -svb6 -scom -sreg -var "var.Binaries" -out "Binaries.wxs"' />

这是 heat.exe 未经任何转换生成的原始 XML:

<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Fragment>
        <DirectoryRef Id="INSTALLDIR">
            <Directory Id="dir7956CF617C38D877C93B5A7D33313596" Name="Folder1">
                <Component Id="cmp1CBAE345A14FB4F0343E1FC307F5EE1D" Guid="CBB5AF6A-D0A2-464D-BFAA-49F9C102A4F4">
                    <File Id="filB5C5E94E5D59CC7DB489F6823F341316" KeyPath="yes" Source="$(var.Binaries)\Folder1\NewTextFile0.txt" />
                </Component>
            </Directory>
            <Directory Id="dir2BA1778353CDCC6DE102110034297AC9" Name="Folder2">
                <Component Id="cmp55726990D3629FC63F840780B5BC7729" Guid="49CAB541-CEB5-423B-89E2-A42D51AD9E7E">
                    <File Id="fil98449FB9E91E1F95E2BA0E6AD712D2E6" KeyPath="yes" Source="$(var.Binaries)\Folder2\NewTextFile1.txt" />
                </Component>
                <Directory Id="dir52EB3739C4D4F7DFB9D67E41E7687374" Name="Folder3">
                    <Component Id="cmpEC9C0276E68BB6794098A24DCF44E0BD" Guid="B495A9DB-3449-45CC-9197-6FD9C8C29C72">
                        <File Id="filB96F911B8B2DE84CED663406AD87D508" KeyPath="yes" Source="$(var.Binaries)\Folder2\Folder3\NewTextFile4.txt" />
                    </Component>
                    <Component Id="cmp873EC3B1583A11ED180C2B5A55082E5E" Guid="B9C57A66-DF0A-480D-83E6-C8E7624974BD">
                        <File Id="fil48004A44BAD8605014735C6A3D6F7004" KeyPath="yes" Source="$(var.Binaries)\Folder2\Folder3\NewTextFile5.txt" />
                    </Component>
                    <Component Id="cmp1614194F7F0694F7AC043F7778BA8109" Guid="B9807535-AC38-41B3-AD9E-A5EB58AC6E12">
                        <File Id="filF11AF0F827CF7E0D02F918F3FD7502AC" KeyPath="yes" Source="$(var.Binaries)\Folder2\Folder3\NewTextFile6.txt" />
                    </Component>
                </Directory>
            </Directory>
        </DirectoryRef>
    </Fragment>
    <Fragment>
        <ComponentGroup Id="CG_Binaries">
            <ComponentRef Id="cmp1CBAE345A14FB4F0343E1FC307F5EE1D" />
            <ComponentRef Id="cmp55726990D3629FC63F840780B5BC7729" />
            <ComponentRef Id="cmpEC9C0276E68BB6794098A24DCF44E0BD" />
            <ComponentRef Id="cmp873EC3B1583A11ED180C2B5A55082E5E" />
            <ComponentRef Id="cmp1614194F7F0694F7AC043F7778BA8109" />
        </ComponentGroup>
    </Fragment>
</Wix>
Run Code Online (Sandbox Code Playgroud)

我有一个 XSL,它更改 File 的 KeyPath 属性no以符合 ICE38 并添加 RegistryValue 以在没有为 File 设置 KeyPath 时修复错误。

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:wix="http://schemas.microsoft.com/wix/2006/wi"
    xmlns="http://schemas.microsoft.com/wix/2006/wi"
    exclude-result-prefixes="xsl wix">

    <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />

    <xsl:strip-space elements="*" />

    <xsl:template match="@*|node()">
        <xsl:copy>
          <xsl:apply-templates select="@*|node()" />
      </xsl:copy>
  </xsl:template>

  <!--File keypath to no and add registry keypath-->
  <xsl:template match="wix:Component/wix:File[@Id]">
    <xsl:copy>
      <xsl:apply-templates select="@*" />
      <xsl:attribute name="KeyPath">
        <xsl:text>no</xsl:text>
    </xsl:attribute>
</xsl:copy>
<RegistryValue Root="HKCU" Key="!(wix.RegKeyLocation)" Name="installed" Type="integer" Value="1" KeyPath="yes" />
</xsl:template>

<xsl:template match="wix:Component/wix:File[not(@Id)]">
    <xsl:copy>
      <xsl:apply-templates select="@*" />
  </xsl:copy>
</xsl:template>

</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)

这是所需的输出

<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Fragment>
        <DirectoryRef Id="INSTALLDIR">
          <Component Id="SomeName" Guid="A99D16EF-80A3-4C98-A91D-3E95C7BD98AE">
            <RemoveFolder Id="dir7956CF617C38D877C93B5A7D33313596" Directory="dir7956CF617C38D877C93B5A7D33313596" On="uninstall" />
            <RemoveFolder Id="dir2BA1778353CDCC6DE102110034297AC9" Directory="dir2BA1778353CDCC6DE102110034297AC9" On="uninstall"/>
            <RemoveFolder Id="dir52EB3739C4D4F7DFB9D67E41E7687374" Directory="dir52EB3739C4D4F7DFB9D67E41E7687374" On="uninstall"/>
            <RegistryValue Root="HKCU" Key="!(wix.RegKeyLocation)" Name="installed" Type="integer" Value="1" KeyPath="yes" />
        </Component>
        <Directory Id="dir7956CF617C38D877C93B5A7D33313596" Name="Folder1">
            <Component Id="cmp1CBAE345A14FB4F0343E1FC307F5EE1D" Guid="CBB5AF6A-D0A2-464D-BFAA-49F9C102A4F4">
                <File Id="filB5C5E94E5D59CC7DB489F6823F341316" KeyPath="no" Source="$(var.Binaries)\Folder1\NewTextFile0.txt" />
                <RegistryValue Root="HKCU" Key="!(wix.RegKeyLocation)" Name="installed" Type="integer" Value="1" KeyPath="yes" />
            </Component>
        </Directory>
        <Directory Id="dir2BA1778353CDCC6DE102110034297AC9" Name="Folder2">
            <Component Id="cmp55726990D3629FC63F840780B5BC7729" Guid="49CAB541-CEB5-423B-89E2-A42D51AD9E7E">
                <File Id="fil98449FB9E91E1F95E2BA0E6AD712D2E6" KeyPath="no" Source="$(var.Binaries)\Folder2\NewTextFile1.txt" />
                <RegistryValue Root="HKCU" Key="!(wix.RegKeyLocation)" Name="installed" Type="integer" Value="1" KeyPath="yes" />
            </Component>
            <Directory Id="dir52EB3739C4D4F7DFB9D67E41E7687374" Name="Folder3">
                <Component Id="cmpEC9C0276E68BB6794098A24DCF44E0BD" Guid="B495A9DB-3449-45CC-9197-6FD9C8C29C72">
                    <File Id="filB96F911B8B2DE84CED663406AD87D508" KeyPath="no" Source="$(var.Binaries)\Folder2\Folder3\NewTextFile4.txt" />
                    <RegistryValue Root="HKCU" Key="!(wix.RegKeyLocation)" Name="installed" Type="integer" Value="1" KeyPath="yes" />
                </Component>
                <Component Id="cmp873EC3B1583A11ED180C2B5A55082E5E" Guid="B9C57A66-DF0A-480D-83E6-C8E7624974BD">
                    <File Id="fil48004A44BAD8605014735C6A3D6F7004" KeyPath="no" Source="$(var.Binaries)\Folder2\Folder3\NewTextFile5.txt" />
                    <RegistryValue Root="HKCU" Key="!(wix.RegKeyLocation)" Name="installed" Type="integer" Value="1" KeyPath="yes" />
                </Component>
                <Component Id="cmp1614194F7F0694F7AC043F7778BA8109" Guid="B9807535-AC38-41B3-AD9E-A5EB58AC6E12">
                    <File Id="filF11AF0F827CF7E0D02F918F3FD7502AC" KeyPath="no" Source="$(var.Binaries)\Folder2\Folder3\NewTextFile6.txt" />
                    <RegistryValue Root="HKCU" Key="!(wix.RegKeyLocation)" Name="installed" Type="integer" Value="1" KeyPath="yes" />
                </Component>
            </Directory>
        </Directory>
    </DirectoryRef>
</Fragment>
<Fragment>
    <ComponentGroup Id="CG_Binaries">
        <ComponentRef Id="SomeName"/>
        <ComponentRef Id="cmp1CBAE345A14FB4F0343E1FC307F5EE1D" />
        <ComponentRef Id="cmp55726990D3629FC63F840780B5BC7729" />
        <ComponentRef Id="cmpEC9C0276E68BB6794098A24DCF44E0BD" />
        <ComponentRef Id="cmp873EC3B1583A11ED180C2B5A55082E5E" />
        <ComponentRef Id="cmp1614194F7F0694F7AC043F7778BA8109" />
    </ComponentGroup>
</Fragment>
</Wix>
Run Code Online (Sandbox Code Playgroud)

所以我想要实现的就是让转换器遍历 xml,找到 Directory 元素的所有 Id 并创建一个新元素,如下所示:

<Component Id="SomeName" Guid="A99D16EF-80A3-4C98-A91D-3E95C7BD98AE">
    <RemoveFolder Id="dir7956CF617C38D877C93B5A7D33313596" Directory="dir7956CF617C38D877C93B5A7D33313596" On="uninstall" />
    <RemoveFolder Id="dir2BA1778353CDCC6DE102110034297AC9" Directory="dir2BA1778353CDCC6DE102110034297AC9" On="uninstall"/>
    <RemoveFolder Id="dir52EB3739C4D4F7DFB9D67E41E7687374" Directory="dir52EB3739C4D4F7DFB9D67E41E7687374" On="uninstall"/>
    <RegistryValue Root="HKCU" Key="!(wix.RegKeyLocation)" Name="installed" Type="integer" Value="1" KeyPath="yes" />
</Component>
Run Code Online (Sandbox Code Playgroud)

我做了一些尝试来实现这一目标,但失败了。一个帮助将不胜感激。

Tim*_*m C 1

从您期望的外观来看,您所需要做的就是一个模板,该元素DirectoryRef...

<xsl:template match="wix:DirectoryRef[@Id='INSTALLDIR']">
Run Code Online (Sandbox Code Playgroud)

然后你可以选择Directory带有xsl:for-each构造的所有元素

<xsl:for-each select=".//wix:Directory[wix:Component/wix:File[@Id]]">
    <RemoveFolder Id="{@Id}" Directory="{@Id}" On="uninstall" />    
</xsl:for-each>
Run Code Online (Sandbox Code Playgroud)

尝试这个 XSLT(我对属性进行了硬编码,Guid因为您需要为此使用某种扩展函数)

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:wix="http://schemas.microsoft.com/wix/2006/wi"
    xmlns="http://schemas.microsoft.com/wix/2006/wi"
    exclude-result-prefixes="xsl wix">

    <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />

    <xsl:strip-space elements="*" />

    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()" />
        </xsl:copy>
    </xsl:template>

    <xsl:template match="wix:DirectoryRef[@Id='INSTALLDIR']">
        <xsl:copy>
         <xsl:apply-templates select="@*" />
         <Component Id="SomeName" Guid="A99D16EF-80A3-4C98-A91D-3E95C7BD98AE">
            <xsl:for-each select=".//wix:Directory[wix:Component/wix:File[@Id]]">
                <RemoveFolder Id="{@Id}" Directory="{@Id}" On="uninstall" />    
            </xsl:for-each>
            <RegistryValue Root="HKCU" Key="!(wix.RegKeyLocation)" Name="installed" Type="integer" Value="1" KeyPath="yes" />
        </Component>
        <xsl:apply-templates select="node()" />
        </xsl:copy>
    </xsl:template>

    <!--File keypath to no and add registry keypath-->
    <xsl:template match="wix:Component/wix:File[@Id]">
        <xsl:copy>
            <xsl:apply-templates select="@*" />
            <xsl:attribute name="KeyPath">
                <xsl:text>no</xsl:text>
            </xsl:attribute>
        </xsl:copy>
        <RegistryValue Root="HKCU" Key="!(wix.RegKeyLocation)" Name="installed" Type="integer" Value="1" KeyPath="yes" />
    </xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)