Unfortunately, the approach above did not work for desktop applications i.e. self contained etc. I am posting the code that worked for me in the end.
Note: I am also including the Wixv4-specific part, in case anyone uses it for that. The harvest directories target does not run in JetBrains Rider, but does via the dotnet cli.
<Project Sdk="WixToolset.Sdk/4.0.0">
<PropertyGroup>
<Platform Condition="'$(RuntimeIdentifier)' == 'win-x64'">x64</Platform>
<Platform Condition="'$(RuntimeIdentifier)' == 'win-x86'">x86</Platform>
</PropertyGroup>
<ItemGroup>
<!-- This is required to make the HarvestDirectories target run -->
<HarvestDirectory Include="obj/" Visible="false" ComponentGroupName="CMP_None" SupressCom="true" SuppressRegistry="true" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\App\App.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="WixToolset.Heat" Version="4.0.1" />
<PackageReference Include="WixToolset.UI.wixext" Version="4.0.1" />
</ItemGroup>
<Target Name="GenerateHarvestDirectories" BeforeTargets="HarvestDirectory">
<MSBuild Projects="%(ProjectReference.Identity)" Targets="GetTargetPath" Properties="Configuration=$(Configuration);RuntimeIdentifier=$(RuntimeIdentifier);SelfContained=$(SelfContained)">
<Output TaskParameter="TargetOutputs" ItemName="PrimaryAssembly" />
</MSBuild>
<Message Text="Harvesting CMP_%(PrimaryAssembly.Filename): %(PrimaryAssembly.RelativeDir)" Importance="high" />
<ItemGroup>
<HarvestDirectory ComponentGroupName="CMP_%(PrimaryAssembly.Filename)" SuppressCom="true" SuppressRegistry="true" SuppressRootDirectory="true" DirectoryRefId="InstallDir" Include="%(PrimaryAssembly.RelativeDir)" />
</ItemGroup>
</Target>
</Project>
The GenerateHarvestDirectories
target runs for each referenced project. Result (paths removed for brevity):
$ dotnet build Installer.wixproj -c Release -r win-x64 --self-contained
MSBuild version 17.5.1+f6fdcf537 for .NET
...
App -> ...\App\bin\Release\net7.0-windows10.0.17763\win-x64\App.dll
Harvesting CMP_App: ...App\bin\Release\net7.0-windows10.0.17763\win-x64\
Installer -> ...\Installer\bin\x64\Release\Installer.msi