Reputation: 3047
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.)
Upvotes: 4
Views: 2663
Reputation: 6218
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.
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.
Upvotes: 2