如何在WiX中对文件序列进行排序?

时间:2013-04-12 08:58:53

标签: wix windows-installer

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

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

谢谢。

2 个答案:

答案 0 :(得分: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>

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

答案 1 :(得分:0)

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

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