2

This question is nearly identical to this one: Is There a Way to Force a Project Reference to .NET Standard Project to a Specific TargetFramework except I am not looking to do anything exotic like force a Framework project to consume a Standard one.

Similar to that question, I have two multi-target projects, a class library which declares:

<TargetFrameworks>netstandard2.1;net48</TargetFrameworks>

And a consuming Unit Test / Console Application project which declares:

<TargetFrameworks>netcoreapp2.1;net48</TargetFrameworks>

The second project references the first in the usual way:

<ProjectReference Include="..\MultiTargetProject\MultiTargetProject.csproj" />

When I build the solution, GetReferenceNearestTargetFrameworkTask generates the following Warning:

NU1702 | ProjectReference 'C:\source\SolutionDir\MultiTargetProject\MultiTargetProject.csproj' was resolved using '.NETFramework,Version=v4.8' instead of the project target framework '.NETCoreApp,Version=v2.1'. This project may not be fully compatible with your project.

Now, based on the previous question, I see there is clearly a way to explicitly define which framework to resolve, and used in combination with some conditional property groups, I can successfully resolve Framework-to-Framework and Standard-to-Core.

My question is:

Should this be necessary - I had assumed the .NET Core project would resolve the .NET Standard reference? What is the logic for GetReferenceNearestTargetFrameworkTask anyway? (I have not been able to find any clear documentation on what the behavior should be.)

wonder
  • 19
  • 1
nicholas
  • 2,969
  • 20
  • 39

1 Answers1

2

In fact, you do not have to complicate this issue too much. The truth is that net standard 2.1 does not support net core 2.1.

See this document.

enter image description here

Net Standard 2.1 supports at least Net Core 3.0.

You only need to change your main project targetframeworks to netcoreapp3.1;net48 or change targetframeworks of your lib project to netstandard2.0;net48 and the warning will disappear.

Sara Liu - MSFT
  • 6,007
  • 1
  • 21
  • 27
  • 2
    Wow, that's amazing. I just try to imagine the product management meetings behind the "naming principles" of a major vs minor version bump: "of course developers will read the docs! there's no possibility for confusion, *at all*" :) Looks right, I will accept as soon as I get a chance to verify. – nicholas Apr 15 '21 at 21:00
  • Well. That is the point. And I have tested it in my side. It is related to the target framework compatibility. – Sara Liu - MSFT Apr 19 '21 at 01:56