gpt4 book ai didi

wix - 如何在Wix工具集中排除文件

转载 作者:行者123 更新时间:2023-12-04 00:25:45 25 4
gpt4 key购买 nike

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

下面是我的代码。

“%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”

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

提前致谢。

最佳答案

您将需要使用XSLT转换。

这样的事情应该为您工作;只需在命令行中包含-t <Path to the xslt file>即可。

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

RemoveExeComponentsTransform.xslt

<?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 - 如何在Wix工具集中排除文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44765707/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com