简体   繁体   中英

When targeting .NET Standard, what exactly can I use from .NET Core and .NET Framework in my project?

I'm working on a class library project whose Target Framework property is set to .NET Standard 2.0.

Based on the documentation , I understand that my code will compile in such a way that it will be compatible with .NET Core 2.0 and .NET Framework 4.6.1. Is that correct?

Does this mean that I can use (and mix together) types and assemblies from .NET Core 2.0 and .NET Framework 4.6.1 in my project? I'm also unsure about which pages from the Microsoft documentation apply to my project.

Would I be correct in thinking that both the following documentation pages reference the types and assemblies that I'll use in my project?

.NET Core 2.0

.NET Framework 4.6.1

I tend to think of .NET Standard as a specification of APIs that are supported for different platforms and .NET versions. It's a “least common denominator” of APIs supported for different platforms. A platform might be .NET Core, .NET framework or Unity.

So let's say your library is Standard 1.0 this means that it can run on a wide range of platforms, but the number of APIs specified in that standard is limited compare to the full .NET Framework or .NET Core.

在此处输入图片说明

It's important to understand that .NET Standard is just a “standard” or a promise of supported APIs for a given platform, you could write an OS for a microwave that supports .NET Standard 1 (implements all API in the standard) and the a class library for .NET Standard 1 work run on that microwave

Have a look at the docs, they have a great table that explains this: https://docs.microsoft.com/en-us/dotnet/standard/net-standard

You can use all the things, you just have to setup your project correctly. Limitations will be that .NET Core objects/methods/etc. will not be directly interoperable with .NET Framework. You will have to work through .NET Standard for indirect interoperability.

This article explains how to target both in the same .sln: .Net Framework and .Net Core in same solution

This article helps you understand .NET Standard in relation to .NET Framework and .NET Core. Essentially, .NET Standard is base library which both .NET Core and .NET Framework sit on. .NET Core and .NET Framework are completely separate libraries, however they are both interoperable through .NET Standard. http://www.codedigest.com/quick-start/9/what-is-netstandard

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