简体   繁体   中英

.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?

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:

在此输入图像描述

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 .

Let's say that you're getting an error like the one above, for example:

Project '*.csproj' targets 'netstandard2.0'. It cannot be referenced by a project that targets '.NETFramework,Version=v4.5.2'.

To resolve the problem, you need to change the project version according to @Martin's table mentioned. In the example above, I would have to go into project settings in the dependent project, and change the .net version to 4.6.1 or higher to correspond to the referenced project's target, eg netstandard 2.0 in the error message.

在此处输入图片说明

在此处输入图片说明

Or, alternatively, downgrade the other project in the same way

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM