Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET Standard 2.0 cannot be referenced in .NET Framework 2.0

I received an error:

'c:......\xxxx.csproj' targets '.NETStandard,Version=v2.0'. It cannot be referenced by a project that targets '.NETFramework,Version=v2.0'. WindowsFormsApp1

How to resolve?

like image 201
mjb Avatar asked Jan 12 '18 04:01

mjb


People also ask

Can I reference .NET framework from .NET standard?

As you said, if you add a . NET framework library to a . NET standard library, then you can no longer run it on . NET Core, but this is a runtime issue rather than an edit time or compile time issue.

Is .NET standard 2.1 compatible with .NET framework?

You cannot consume a . Net Standard 2.1 assembly in any . Net Framework Version because the . NET Framework (even the last ever version, 4.8) does not implement .

Is .NET 5 compatible with .NET standard 2?

NET 5 and all future versions will continue to support . NET Standard 2.1 and earlier.


1 Answers

Unfortunately you cannot reference a .NET Standard library in .NET 2.0 project. The reason is that .NET 2.0 is missing many key API and hence cannot implement the .NET Standard 2.0 contract. If you cannot modify the source of the .NET Standard 2.0 library, the only option is upgrading your project to .NET Framework 4.6.1 or later.

The most useful reference is the .NET Standard Compatibility matrix listed in the official documentation, which shows the version compatibility with different .NET implementations:

enter image description here

From here you can see that the first .NET Framework version that can reference a .NET Standard libary is 4.5, and it still cannot reference Standard 2.0, because it is still missing some of the APIs.

For further details check out the .NET Standard documentation.

like image 106
Martin Zikmund Avatar answered Nov 15 '22 16:11

Martin Zikmund