microsoft / microsoft/MSBuildSdks

[NoTargets] Can't build with BuildProjectReferences=false when referencing a multi-targeted project

Open
#427 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
508
Forks
94
Avg merge
6h 40m
Merged PRs (30d)
2

Description

Summary

When referencing a multi-targeted project from a NoTargets project, you can't build with BuildProjectReferences=false.

Repro

library\library.csproj:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFrameworks>net7.0;net472</TargetFrameworks>
  </PropertyGroup>

</Project>

deployment\deployment.proj:

<Project Sdk="Microsoft.Build.NoTargets">

  <PropertyGroup>
    <TargetFramework>net7.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <ProjectReference Include="..\library\library.csproj" />
  </ItemGroup>

</Project>
>dotnet build deployment -p:BuildProjectReferences=false
MSBuild version 17.5.0-preview-23061-01+040e2a90e for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.
..\library\library.csproj : error MSB4057: The target "GetTargetPath" does not exist in the project.

Build FAILED.

..\library\library.csproj : error MSB4057: The target "GetTargetPath" does not exist in the project.
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:00.80

Other details

Setting SkipGetTargetFrameworkProperties=false on the ProjectReference fixes the problem. The culprit appears to be this line, but I'm not sure what the impact of removing that would be.

This came up because QuickBuild (MS internal build tool for large repos) invokes MSBuild with BuildProjectReferences=false.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/NoTargets/Sdk/Sdk.props at the linked line, then reproduce the failure using the deployment.proj and library.csproj examples with BuildProjectReferences=false. Trace the ProjectReference behavior for the multi-targeted library and verify that the build completes without MSB4057 while preserving the relevant target-framework behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.