Search code examples
.net-coremsbuildwixwix4

Error WIX0150: Undefined preprocessor variable when using ProjectReference against a multi-targeted project


I have two projects: ConsoleApp1 and Package1. Both are the "empty" project templates for a net7.0 and wix4 setup project respectively. ConsoleApp1 is modified to have <TargetFrameworks>net7.0</TargetFrameworks>. Adding a project reference from Package1 and trying to access via preprocessor, binding, or otherwise the files from ConsoleApp1 is unsuccessful.

ConsoleApp1.csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFrameworks>net7.0</TargetFrameworks>
  </PropertyGroup>
</Project>

Package1.wixproj

<Project Sdk="WixToolset.Sdk/4.0.0-rc.1">
  <ItemGroup>
    <ProjectReference Include="..\ConsoleApp1\ConsoleApp1.csproj"/>
  </ItemGroup>
</Project>

ExampleComponents.wxs

<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
  <Fragment>
    <ComponentGroup Id="ExampleComponents" Directory="INSTALLFOLDER">
      <Component>
        <File Source="ExampleComponents.wxs" />
        <File Source="$(var.ConsoleApp1.TargetPath)" KeyPath="yes" />
      </Component>
    </ComponentGroup>
  </Fragment>
</Wix>

Things that don't work:

  • Setting TargetFramework or TargetFrameworks in the wixproj
  • Using AdditionalProperties="TargetFramework=net7.0" in the wixproj ProjectReference
  • Wailing in lamentation at the barren wix4 documentation page

If I use <TargetFramework> instead of <TargetFrameworks> in the console project, the error resolves - but I need to multi-target. How can I depend with a ProjectReference on a multi-targeted project with wix4?


Solution

  • Use SetTargetFramework to avoid multi-targeting in the project reference. I'm not sure why AdditionalProperties fails but SetTargetFramework succeeds.

    Updated Package1.wixproj:

    <Project Sdk="WixToolset.Sdk/4.0.0-rc.1">
      <ItemGroup>
        <ProjectReference Include="..\ConsoleApp1\ConsoleApp1.csproj">
          <SetTargetFramework>TargetFramework=net7.0</SetTargetFramework>
        </ProjectReference>
      </ItemGroup>
    </Project>