【问题标题】:Can I exclude a specific file name with Wix Heat using transforms?我可以使用转换排除带有 Wix Heat 的特定文件名吗?
【发布时间】:2023-03-02 23:49:01
【问题描述】:

是否可以通过 Wix 使用转换排除特定文件名? 我可以排除 包含 某个字符串的文件,但这会排除与该字符串匹配的任何文件名。例如,我可以使用以下内容排除 file.exe;

<xsl:key name="fileexe-search" match="wix:Component[contains(wix:File/@Source, 'file.exe')]" use="@Id"/>

但这也会排除名称中带有 file.exe 的文件,例如 file.exe.config。

谢谢。

【问题讨论】:

    标签: wix installation heat


    【解决方案1】:

    虽然@Yan 提供的答案有效,但我更喜欢使用更简单的 C#。

    <xsl:stylesheet version="1.0"
        ...
        xmlns:my="urn:my-installer">
        ...
    
    <msxsl:script language="C#" implements-prefix="my">
    <msxsl:using namespace="System.IO" />
    <![CDATA[
    public bool EndsWith(string str, string end)
    {
      if (string.IsNullOrEmpty(str))
        return false;
    
      if (string.IsNullOrEmpty(end))
        return false;
    
      return str.EndsWith(end);
    }
    ]]>
    </msxsl:script> 
    
        ...
    

    使用示例:

    <xsl:key name="ignored-components-search" match="wix:Component[my:EndsWith(wix:File/@Source, '.pssym')                                                   
                                                   or my:EndsWith(wix:File/@Source, '.pdb')
                                                   or my:EndsWith(wix:File/@Source, '.cs')
                                                   or my:EndsWith(wix:File/@Source,'.xml')                                                      
                                                     ]" use="@Id" />
    

    【讨论】:

    • 感谢@derwasp,我选择了@Yan 的回答,因为我不知道如何使用热量启用脚本执行。我不断收到heat.exe : error HEAT5055 : Error applying transform exclude.xsl to harvested WiX: Execution of scripts was prohibited. Use the XsltSettings.EnableScript property to enable it. 。我敢肯定,如果我能弄清楚这一点,这会很好用。
    【解决方案2】:

    看起来您应该使用ends-with 而不是contains。但是ends-with 在 XSLT 1.0 中不存在。 :)

    This answer 提供了足够的细节来了解如何实现它。基本上它是substring 和string-length 函数的组合。

    此外,您还应该考虑在比较之前对大小写进行标准化。也就是说,最好将两个字符串都小写(或大写) - 原始字符串和以它结尾的字符串。 This post 可以让你知道怎么做。

    记住这一切,你最终会得到类似这样的东西:

    <!-- The starting backslash is there to filter out files like 'abcfile.exe' -->
    <!-- Besides, it's lower-cased to ease comparison -->
    <xsl:variable name="FileName">\file.exe</xsl:variable>
    <xsl:variable name="ABC">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable>
    <xsl:variable name="abc">abcdefghijklmnopqrstuvwxyz</xsl:variable>
    
    <xsl:key name="fileexe-search" match="wix:Component[translate(substring(wix:File/@Source, string-length(wix:File/@Source) - string-length($FileName) + 1), $ABC, $abc) = $FileName]" use="@Id"/>
    

    【讨论】:

    • 你的回答让我走上了正确的道路。出于某种原因,每当我使用变量时,都会出现错误; heat.exe : error HEAT5055 : Error applying transform exclude.xsl to harvested WiX: Variables cannot be used within this expression. 所以我用实际的文件名替换了变量。对于我的排除,我保证文件名的大小写,所以我没有实现大小写比较。 &lt;xsl:key name="fileexe-search" match="wix:Component[translate(substring(wix:File/@Source, string-length(wix:File/@Source) - string-length('\file.exe') + 1), $ABC, $abc) = '\file.exe']" use="@Id"/&gt;
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多