dotnet / dotnet/msbuild

Project-to-project reference fails to detect correct multi-target framework if <TargetFramework> is defined

Open
#7,856 15 comments 4 reactions 0 assignees View on GitHub
Area: BuildCheck triaged
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:

![image](https://user-images.githubusercontent.com/1291962/181686955-5442ded6-a2b4-4788-a8ca-bc37c885c08b.png)

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

![image](https://user-images.githubusercontent.com/1291962/181687864-5fb79def-c3bf-4009-8588-a0c748ac7e1d.png)

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.