dotnet / dotnet/msbuild

The _GetProjectReferenceTargetFrameworkProperties target doesn't work for multiple projects with same identity

Open
#8,270 0 comments 0 reactions 0 assignees View on GitHub
gathering-feedback triaged
Dominant language
C#
Stars
5.5k
Forks
1.5k
Avg merge
1d 8h
Merged PRs (30d)
141

Description

The [`_GetProjectReferenceTargetFrameworkProperties` target](https://github.com/dotnet/msbuild/blob/a6f6699d1f70bf79db82030938d2c5e52d1e4d2e/src/Tasks/Microsoft.Common.CurrentVersion.targets#L1706) is responsible for annotating ProjectReference items with various metadata (`SetTargetFramework`, `UndefineProperties`, ...). When specifying multiple `ProjectReference` items with the same identity, the metadata isn't applied which results in the wrong target framework, runtime identifier and self contained settings being passed to the project.

Example:
```xml


net7.0




```

### Error
As the `TargetFramework` global property isn't undefined, `net7.0` is passed down to the child project, which only targets `net6.0` and `net5.0`.

```
C:\temp\tfm\a>dotnet build
MSBuild version 17.4.0+18d5aef85 for .NET
Determining projects to restore...
All projects are up-to-date for restore.
C:\Program Files\dotnet\sdk\7.0.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(267,5): error NETSDK1005: Assets file 'C:\temp\tfm\b\o
bj\project.assets.json' doesn't have a target for 'net7.0'. Ensure that restore has run and that you have included 'net7.0' in the TargetFrameworks for your project. [
C:\temp\tfm\b\b.csproj::TargetFramework=net7.0]

Build FAILED.
```

Minimal repro: [tfm.zip](https://github.com/dotnet/msbuild/files/10320741/tfm.zip)

Reason for that are the `'@(AnnotatedProjects)' == '%(Identity)'` checks in the condition statements: https://github.com/dotnet/msbuild/blob/main/src/Tasks/Microsoft.Common.CurrentVersion.targets#L1891

It's not clear to me why these statements exist in the first place. When I remove them, everything works as expected. Those were added by @AndyGerlicher in https://github.com/dotnet/msbuild/commit/57ae27cf0812bf262c6f8be456ed527a1542dba7. I assume that those were necessary with a previous version of MSBuild and can be removed now.

cc @rainersigwald

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.