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?
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.
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 .
NET 5 and all future versions will continue to support . NET Standard 2.1 and earlier.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With