Project-to-project reference fails to detect correct multi-target framework if <TargetFramework> is defined
- Dominant language
- C#
- Stars
- 5.5k
- Forks
- 1.5k
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 141
Description
If a project has both `` and `` defined, other projects cannot correctly reference the project's target framework that is different than what `` specifies.
Building the project with both properties defined does correctly produce the binaries for each targeted framework. It's just project-to-project references that doesn't work.
Create project A (ClassLibrary1) like so:
```xml
net6.0-windows
net6.0;net6.0-windows
enable
enable
```
and project B (ClassLibrary2) like so:
```xml
net6.0
enable
enable
```
Project B (ClassLibrary2) will fail to build with the following error:
```
Project '..\ClassLibrary1\ClassLibrary1.csproj' targets 'net6.0-windows'. It cannot be referenced by a project that targets '.NETCoreApp,Version=v6.0'. ClassLibrary2 C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets 1806
```
From the binlog, it seems MSBuild will treat project A as having a single target framework:

If I remove `` in project A, then MSBuild correctly treats project A as having multiple target frameworks:

Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.