Imagine that a project includes thousands of files to install, it's impossible to add <Component> <File> element one by one manually, we can use the heat.exe tools to generate it automatically. Execute command below.
cd C:\Program Files (x86)\WiX Toolset v3.11\bin start heat.exe dir "C:\MyCode\RiskSpectrumSDP\...\publish" -dr INSTALLFOLDER -cg sdpapp -gg -sfrag -scom -sreg -template:fragment -var var.SDPBasePath -out C:\Publish\myListFile.wxs
Even if there are not so many files, such as only ten or twenty, still recommend use heat.exe to generate file list, we don't need to set GUID to every <Component> <File> manually, it's faster and no errors.
Can check the parameters of Heat here: Harvest Tool (Heat)
Tip: Generate file list automatically before every build
Add below code to the .wixproj file, it will generate a file named "HeatGeneratedFileList.wxs" every time before build the Wix project.
<Target Name="BeforeBuild"> <HeatDirectory Directory="..\SDP.WebApp\bin\Release\netcoreapp2.2\publish\ClientApp" PreprocessorVariable="var.HarvestPath" RunAsSeparateProcess="$(RunWixToolsOutOfProc)" OutputFile="HeatGeneratedFileList.wxs" ComponentGroupName="HeatGenerated" DirectoryRefId="WEBFOLDER" AutogenerateGuids="true" ToolPath="$(WixToolPath)" SuppressFragments="true" SuppressRegistry="true" SuppressRootDirectory="true" /> </Target>
Can check parameters here: HeatDirectory Task
If want to set the "Directory" as a variable, should change the code like below. Warp the "HeatDirectory" innner "ItemGroup", and change "Directory" to "Include"
<Target Name="BeforeBuild"> <ItemGroup> <HeatDirectory Include="$(WebBasePath)"> <PreprocessorVariable>var.WebBasePath</PreprocessorVariable> <RunAsSeparateProcess>$(RunWixToolsOutOfProc)"</RunAsSeparateProcess> <OutputFile>RWWebFileList.wxs</OutputFile> <ComponentGroupName>webapp</ComponentGroupName> <DirectoryRefId>WEBFOLDER</DirectoryRefId> <AutogenerateGuids>true</AutogenerateGuids> <ToolPath>$(WixToolPath)</ToolPath> <SuppressFragments>true</SuppressFragments> <SuppressCom>true</SuppressCom> <SuppressRegistry>true</SuppressRegistry> <SuppressRootDirectory>true</SuppressRootDirectory> </HeatDirectory> </ItemGroup> </Target>
Reference:
Include all Files in Bin folder in Wix installer
WIX HeatDirectory Task - Setting the preprocessorVariable