Reputation: 1223
I have inherited a .NET application. This application has a Visual Studio 2019 solution with many projects. When I open the solution, I can see the multiple warnings that say:
ProjectReference {path} was resolved using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETStandard,Version=v2.0'. This project may not be fully compatible with your project.
In Visual Studio 2019, I can see that the Target framework listed in the project properties is ".NET Standard 2.0". Which, means I have the framework installed on my machine. When I open one of the .csproj files in Notepad that throws this warning, I see that the TargetFramework
element is set to netstandard2.0
. At this point, everything looks correct. However, I don't understand why I'm receiving the error above or how to fix it.
How do I get rid of the warning shown above?
Upvotes: 1
Views: 2441
Reputation: 4906
That means your .NET Standard 2.0 project has reference dependencies to other projects that have .NET Framework 4.6.1 as their target.
All of .NET Standard until v2.0 projects cannot reliably depend on other projects that use non .NET Standard projects such as .NET Framework and .NET Core projects. The hierarchy of target dependencies is incorrect, because .NET Standard projects has higher abstractions (more general) than .NET Framework and .NET Core. The non .NET Standard project can have reference dependencies to .NET Framework and .NET Core projects.
Based on this fact above (and see the docs below) You can force .NET Standard project to depend on.NET Framework/NET Core projects, but there will be no guarantee that it will be compatible, therefore it won't be guaranteed to work especially at runtime.
The .NET Standard 2.1 are only compatible with .NET Core 3.0 and later.
See also this official doc of .NET Standard: https://learn.microsoft.com/en-us/dotnet/standard/net-standard
See the official blog post of .NET Standard 2.1 announcement: https://devblogs.microsoft.com/dotnet/announcing-net-standard-2-1/
Upvotes: 2