【问题标题】:How can I sort file sequence in WiX?如何在 WiX 中对文件序列进行排序?
【发布时间】:2013-04-14 16:26:34
【问题描述】:

文件表中的 AFAIK 文件序列(在 MSI 文件中)对卸载/安装所需的时间有影响:如果具有相同目标目录的文件条目按顺序放置在文件表中,则安装程序执行卸载/安装所需的时间更少比那些文件分散在文件表中的时候。

但是,我的 wix 项目构建的安装程序似乎属于后一种情况。它的文件条目具有相同的目标目录分散在文件表中。有没有办法对这些文件条目进行排序,以便它们按顺序放置在文件表中? (我的.wxs文件是由heat.exe生成的)

谢谢。

【问题讨论】:

    标签: wix windows-installer


    【解决方案1】:

    加热工具提供了在加热结束时运行自定义 XSLT 转换的能力。这是一个非常强大的功能,因为它为您提供了一种对结果进行任何操作的方法。例如,以下 XSL 会将文件 ID 更改为所有父文件夹 + 文件名的串联。

    <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"
                xmlns:wix="http://schemas.microsoft.com/wix/2006/wi"
                xmlns:my="my:my">
    
      <xsl:output method="xml" indent="yes" />
    
      <xsl:strip-space elements="*"/>
    
      <xsl:template match="@*|node()">
        <xsl:copy>
          <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
      </xsl:template>
    
      <xsl:template match='wix:File'>
        <xsl:variable name='fileId'>
          <xsl:value-of select="/wix:Wix/wix:Fragment/wix:DirectoryRef/@Id"/>_<xsl:value-of select="translate(substring-after(@Source, '\'), '\- ', '_')"/>
        </xsl:variable>
        <xsl:copy>
          <xsl:apply-templates select="@*"/>
          <xsl:attribute name="Id">
            <xsl:value-of select="$fileId"/>
          </xsl:attribute>
        </xsl:copy>
      </xsl:template>
    
      <xsl:template match='wix:Directory'>
        <xsl:variable name='parentPath'>
          <xsl:for-each select='ancestor::wix:Directory/@Name'>
            <xsl:value-of select="concat(.,'_')"/>
          </xsl:for-each>
        </xsl:variable>
        <xsl:copy>
          <xsl:apply-templates select="@*"/>
          <xsl:attribute name="Id">
            <xsl:value-of select="/wix:Wix/wix:Fragment/wix:DirectoryRef/@Id"/>_<xsl:value-of select="translate($parentPath, '- ', '__')"/><xsl:value-of select="translate(@Name, '- ', '__')"/>
          </xsl:attribute>
    
          <xsl:apply-templates select="*"/>
        </xsl:copy>
      </xsl:template>
    
    </xsl:stylesheet>
    

    这种方法不能保证 ID 的唯一性,但对我来说效果很好。

    【讨论】:

    • 感谢您提供好的代码。 :) 效果很好,我为自己定制了它。
    【解决方案2】:

    WiX 工具集中没有内置任何东西可以以特定方式排序。但是,如果您有经验证据表明应该使用更好的排序算法,那么发送到 wix-devs@lists.sourceforge.net 邮件列表将是一件好事。 WiX 工具集应该自动进行最佳优化。

    HACK:您可以尝试按字母顺序对File/@Id 进行排序,以控制当前版本的 WiX 工具集的顺序。这可能适用于所有版本的 WiX 工具集,也可能不适用。

    【讨论】:

    • 我希望 heat.exe 可以在 File/@Id 中包含父目录名称,如 WiX:Windows Installer XML 开发人员指南,第 2 章中所建议的那样。我有太多文件无法编写它们手动标识。
    • 您可能可以通过使用 XSLT 获得此信息。由于 XSL 转换可能非常复杂,因此只需要一些体操。 :)
    猜你喜欢
    • 2018-07-03
    • 1970-01-01
    • 1970-01-01
    • 2021-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-01
    • 1970-01-01
    相关资源
    最近更新 更多