收集文件以便在PerUser安装程序中使用

时间:2016-03-07 16:01:21

标签: 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.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>

我有一个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>

这是Desired输出

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

所以我想要实现的是变换器循环遍历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>

我做了一些尝试来实现这一目标但却失败了。我们将不胜感激。

1 个答案:

答案 0 :(得分:1)

从您期望的外观来看,您需要做的就是app.put('updatebox/:box/:supplies', function (req, res) { var boxReq = req.params.box; var suppliesReq = req.params.supplies; boxModel .find({box: boxReq}) .findOneAndUpdate({supplies: suppliesReq}, { $set: { box: "Box 2" } }, {new: true}, function (err, doc) { if (err) { console.log("Something wrong when updating data!"); } res.json(doc); }); }) 元素的模板......

DirectoryRef

然后您可以使用<xsl:template match="wix:DirectoryRef[@Id='INSTALLDIR']"> 构造

选择所有Directory元素
xsl:for-each

试试这个XSLT(我对<xsl:for-each select=".//wix:Directory[wix:Component/wix:File[@Id]]"> <RemoveFolder Id="{@Id}" Directory="{@Id}" On="uninstall" /> </xsl:for-each> 属性进行了硬编码,因为你需要使用某种扩展函数)

Guid