您可以通过将 BeforeBuild 目标添加到您的 wixproj 文件来执行类似的操作:
<Target Name="BeforeBuild">
<ItemGroup>
<FileThatExists Include="..\Files\**\FileThatExists.txt"/>
</ItemGroup>
<PropertyGroup>
<Build>@(FileThatExists->'%(RecursiveDir)')</Build>
<BasePath>..\Files\$(Build)\</BasePath>
<DefineConstants>
$(DefineConstants);
Build=$(Build);
BasePath=$(BasePath);
</DefineConstants>
</PropertyGroup>
<HeatDirectory
OutputFile="HarvestedCopyFiles.wxs"
DirectoryRefId="INSTALLFOLDER"
ComponentGroupName="HarvestedCopyFilesComponent"
SuppressCom="true"
Directory="$(BasePath)"
SuppressFragments="true"
SuppressRegistry="true"
SuppressRootDirectory="true"
AutoGenerateGuids="false"
GenerateGuidsNow="true"
ToolPath="$(WixToolPath)"
PreprocessorVariable="var.BasePath"
/>
</Target>
它的作用是通过巧妙地使用 ItemGroup 元数据属性来计算构建文件夹的 #。您也可以创建另一个目标来获取该文件夹名称,并且您应该能够在 SO 上找到一些示例。
我们将 Build 属性值设置为我们制作的项目的 RecursiveDir 元数据,然后还定义 BasePath 值。
接下来,我们将更新DefineConstants 属性中包含的值。这是允许您将变量键值对传递给 Candle wix 编译器的属性,它允许您在安装程序源代码中使用 $(var.Build) 和 $(var.BasePath) 之类的语法。
最后,我们调用 HeatDirectory 任务,它将收集您的 build# 文件夹并生成 HarvestedCopyFiles.wxs 文件。
我想建议定义 HarvestDirectory 目标使用的项目“HarvestDirectory”,如果存在一个或多个 HarvestDirectory 项目,该目标将运行。
为此,您只需<HeatDirectory>
将
<PropertyGroup>
<HarvestDirectoryAutogenerateGuids>true</HarvestDirectoryAutogenerateGuids>
<HarvestDirectoryGenerateGuidsNow>true</HarvestDirectoryGenerateGuidsNow>
</PropertyGroup>
<ItemGroup>
<HarvestDirectory Include="$(BasePath)">
DirectoryRefId="INSTALLFOLDER"
ComponentGroupName="HarvestedCopyFilesComponent"
PreprocessorVariable="var.BasePath"
SuppressCom="true"
SuppressRegistry="true"
SuppressRootDirectory="true"
</HarvestDirectory>
</ItemGroup>
我更喜欢这种方法,因为它会自动将生成的文件包含在您的编译源中,因此您不必在项目中包含不存在的文件。