是的,您必须列出每个有效负载。将它们放在 PayloadGroup 中很方便。
有很多方法可以生成 PayloadGroup。一种方法是使用/滥用热量来收获目录。这与为安装项目获取目录的方式相同。
作为一个例子,我们来打包 WiX 的 bin 目录。
<ExePackage Id="MyPackageId" SourceFile="$(env.WiX)bin/dark.exe" Compressed="yes">
<PayloadGroupRef Id="MyPayloadGroupId"/>
</ExePackage>
如果您使用 MSBuild(包括通过 Visual Studio),您可以通过在项目文件中添加如下内容来配置收获:
<ItemGroup>
<HarvestDirectory Include="$(WIX)/bin">
<ComponentGroupName>MyPayloadGroupId</ComponentGroupName>
<PreprocessorVariable>var.MyPayloadSourceDirectory</PreprocessorVariable>
<Transforms>FilesToPayloads.xsl</Transforms>
<SuppressRegistry>true</SuppressRegistry>
<!-- Hide from VS Solution Explorer -->
<InProject>false</InProject>
</HarvestDirectory>
</ItemGroup>
当构建运行时,它将输出 .wsx(在 obj 中)文件夹添加到构建中。 (你不需要看到它。)
请注意,它使用预处理器变量来给出源文件的实际位置。要传递该值,请在项目属性中定义它。或者,作为 .wixproj 中的 XML:
<DefineConstants>Debug;MyPayloadSourceDirectory=C:/Program Files (x86)/WiX Toolset v3.8/bin</DefineConstants>
最后,热量将应用于其正常收获输出的 XSL 转换 (FilesToPayloads.xsl):
<xsl:stylesheet version="1.0"
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">
<xsl:template match="/">
<Wix>
<Fragment>
<xsl:apply-templates select="*" />
</Fragment>
</Wix>
</xsl:template>
<xsl:template match="//wix:DirectoryRef">
<PayloadGroup>
<xsl:attribute name="Id">
<xsl:value-of select="/wix:Wix/wix:Fragment/wix:ComponentGroup/@Id"/>
</xsl:attribute>
<xsl:apply-templates select="*" />
</PayloadGroup>
</xsl:template>
<xsl:template match="//wix:File">
<Payload>
<xsl:attribute name="SourceFile">
<xsl:value-of select="@Source"/>
</xsl:attribute>
</Payload>
</xsl:template>
</xsl:stylesheet>
这是从 File 到 Payload 以及周围的 DirectoryRef 到 PayloadGroup 的相当简单的音译。