如何在Wix工具集中排除文件 [英] how to exclude files in Wix toolset

查看:110
本文介绍了如何在Wix工具集中排除文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在收集heat.exe的文件时,我想从输入文件夹中排除扩展名为.exe的文件,因为它首先会获取文件夹中的所有文件.

While harvesting files for heat.exe, I would like to exclude the files with the extension .exe from the input folder since it fetches all the files in the folder at first place.

下面是我的代码.

%WIX_PATH%\ Heat.exe"目录%input_folder%" -cg SourceProjectComponents -dr安装-scom -sreg -srd -var var.BasePath -gg -sfrag -var var.BasePath -out%output_folder% \ Output.wxs"

"%WIX_PATH%\Heat.exe" dir "%input_folder%" -cg SourceProjectComponents -dr INSTALLLOCATION -scom -sreg -srd -var var.BasePath -gg -sfrag -var var.BasePath -out "%output_folder%\Output.wxs"

PS:input_folder由几个.dll和.exe文件组成.因此无法单独收集文件.

PS: the input_folder consists of severall .dll and .exe files. hence individual harvesting of the file wasn't possible.

先谢谢了.

推荐答案

您将需要使用XSLT转换.

You will need to use an XSLT transform.

类似的事情应该对您有用;只需在命令行中添加-t <Path to the xslt file>即可.

Something like this should work for you; Just include -t <Path to the xslt file> in your command line for heat.

此XSLT输出一个新XML文件,该文件包含输入的所有XML节点,除非任何节点是具有.exe <File>元素的<Component>元素.

This XSLT outputs a new XML file that contains all XML nodes of the input, except if any nodes are <Component> elements with .exe <File> elements.

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
    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"

    version="1.0" 
    exclude-result-prefixes="xsl wix"
>

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

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

    <!--
    Find all <Component> elements with <File> elements with Source="" attributes ending in ".exe" and tag it with the "ExeToRemove" key.

    <Component Id="cmpSYYKP6B1M7WSD5KLEQ7PZW4YLOPYG61L" Directory="INSTALLDIR" Guid="*">
        <File Id="filKUS7ZRMJ0AOKDU6ATYY6IRUSR2ECPDFO" KeyPath="yes" Source="!(wix.StagingAreaPath)\ProofOfPEqualsNP.exe" />
    </Component>

    Because WiX's Heat.exe only supports XSLT 1.0 and not XSLT 2.0 we cannot use `ends-with( haystack, needle )` (e.g. `ends-with( wix:File/@Source, '.exe' )`...
    ...but we can use this longer `substring` expression instead (see https://github.com/wixtoolset/issues/issues/5609 )
    -->
    <xsl:key
        name="ExeToRemove"
        match="wix:Component[ substring( wix:File/@Source, string-length( wix:File/@Source ) - 3 ) = '.exe' ]"
        use="@Id"
    /> <!-- Get the last 4 characters of a string using `substring( s, len(s) - 3 )`, it uses -3 and not -4 because XSLT uses 1-based indexes, not 0-based indexes. -->

    <!-- We can also remove .pdb files too, for example: -->
    <xsl:key
        name="PdbToRemove"
        match="wix:Component[ substring( wix:File/@Source, string-length( wix:File/@Source ) - 3 ) = '.pdb' ]"
        use="@Id"
    />

    <!-- By default, copy all elements and nodes into the output... -->
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()" />
        </xsl:copy>
    </xsl:template>

    <!-- ...but if the element has the "ExeToRemove" key then don't render anything (i.e. removing it from the output) -->
    <xsl:template match="*[ self::wix:Component or self::wix:ComponentRef ][ key( 'ExeToRemove', @Id ) ]" />

    <xsl:template match="*[ self::wix:Component or self::wix:ComponentRef ][ key( 'PdbToRemove', @Id ) ]" />

</xsl:stylesheet>

这篇关于如何在Wix工具集中排除文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆