.NET 标准,.NET 核心,PCL
.NET Standard, .NET Core, PCL
.NET Standard 一直是一个令人困惑的概念。标准 .NET 库格式的想法听起来很棒。但是,尚不清楚它到底是什么。 Visual Studio 中现在有 .NET Core 和 .NET Standard Class 库项目模板,以及旧的 PCL 项目。我还发现,如果您进入项目设置,您可以将现有的 PCL 库切换到 .NET Standard。不清楚 .NET 标准是否是一个库?或 DLL 格式。
我要问的基本问题是 我们应该针对哪种类型的库?我主要是为 Xamarin 项目做这件事,但如果我们可以的话那就太好了与其他平台共享这些库,尤其是 .NET Core 和 UWP。令人困惑的是,为什么微软同时推出了两种看似相同的 Class 库类型:.NET Core 和 .NET Standard。
定义
NET Core - 基于 .NET 的运行时环境,符合 .NET 标准 API 定义。
PCL - 一种基于 .NET 的库格式,受多种运行时环境支持,包括 .NET、Mono、UWP 等
.NET 标准(定义 1) - 一组用于基于 .NET 的运行时环境的标准 API 定义
.NET Standard(定义 2) - 一种基于 .NET 的库格式,受多种运行时环境支持,包括 .NET、Mono、UWP 等,它是PCL 格式。在 Visual Studio 中,可以通过进入项目属性并编辑目标框架,将 PCL 库转换为 .NET Standard 库。
我相信此资源可以回答您的大部分问题:
https://docs.microsoft.com/en-us/dotnet/articles/standard/library
The .NET Standard Library is a formal specification of .NET APIs that are intended to be available on all .NET runtimes. The motivation behind the Standard Library is establishing greater uniformity in the .NET ecosystem.
据我了解,其他库类型是特定于平台的,而 .NET 标准在某种程度上与平台无关。
如果您希望您的代码在不同平台上可用,那么 .NET 标准似乎是理想的选择,但请密切注意其他平台支持的 .NET 标准版本(请参阅 [=22= 中的 table ]).
希望对您有所帮助
标准版针对一组特定的 API 类似于 Android API 版本。 nuget 库只是元数据包,包含所有符合标准的库。
MSDEV 节目中的 Scott Hunter 很好地解释了这个概念。值得一试 - http://msdevshow.com/2016/07/dot-net-core-with-scott-hunter/
这边的文档确实比较混乱,但是大致可以这样理解:
PCL:针对一组平台的库(具有这些平台的 API 的 'least common denominator')。所以在写 PCL 时,你是说我想针对平台 A、B、C
.NET 标准:一组 'standard' API 而不是一个平台。所以基本上你不关心平台,只关心标准(版本 1.3、1.6 ...),你的代码将在支持它的所有平台上运行。
- .NET core这里不要混淆,是.NET framework的'another version'。 .NET 标准将跨运行时工作(.NET 框架、.NET 核心、Mono)
所以我想 .NET 标准是可行的方式:)
来自 Samuel Englard (https://github.com/dotnet/corefx/issues/973#issuecomment-249582799):
.NET DLLs are formatted according to ECMA-335 (Better known as the
Common Language Infrastructure). This format is true across all
platforms we call .NET; Full Framework, Core, Xamarin, Mono,
Silverlight, etc.
The reason you couldn't use a DLL compiled against one platform with
another was that the format didn't specify APIs (generally speaking).
So while they could all read the DLL you'd run into issues of class
XYZ being in namespace A.B.C on one platform and in namespace D.E.F on
another, if it existed at all.
PCLs "solved" this by doing two things:
They used Type Forwarding so that even though you wrote your code expecting class XYZ in namespace A.B.C, it could be found on platforms that had it elsewhere.
It limited what APIs you could use to the lowest common set shared by all the platforms you wanted.
Taking a PCL and converting it to a .NET Standard project is not a
recompile because of output format but because of the meta data
included (Type Forwarding particularly).
所以,我认为 .NET Standard 库本质上与 PCL 库没有什么不同,除了它们在不同的标准化 API 集之上放置了一个层,并且这些 API 可以实现不同的指针(类型转发)。
.NET Core 当然是一个运行时环境,但我认为它与 .NET Standard 非常接近。除了实现 .NET Standard API 之外,我认为它与它没有任何特殊关系。
In my mind, it is generally better to target a .NET Standard Class library because this will be compatible across multiple platforms。例如,如果您以 .NET Core 为目标,则无法在 UWP 中引用此程序集类型。你会看到这个:
但是,如果您在纯 .NET Core 环境中工作,您可能会发现有特定于 .NET Core 运行时环境的可用 API,因此有必要直接以 .NET Core 为目标。
请看这个词汇表:
https://github.com/dotnet/corefx/blob/master/Documentation/project-docs/glossary.md
.NET Standard 一直是一个令人困惑的概念。标准 .NET 库格式的想法听起来很棒。但是,尚不清楚它到底是什么。 Visual Studio 中现在有 .NET Core 和 .NET Standard Class 库项目模板,以及旧的 PCL 项目。我还发现,如果您进入项目设置,您可以将现有的 PCL 库切换到 .NET Standard。不清楚 .NET 标准是否是一个库?或 DLL 格式。
我要问的基本问题是 我们应该针对哪种类型的库?我主要是为 Xamarin 项目做这件事,但如果我们可以的话那就太好了与其他平台共享这些库,尤其是 .NET Core 和 UWP。令人困惑的是,为什么微软同时推出了两种看似相同的 Class 库类型:.NET Core 和 .NET Standard。
定义
NET Core - 基于 .NET 的运行时环境,符合 .NET 标准 API 定义。
PCL - 一种基于 .NET 的库格式,受多种运行时环境支持,包括 .NET、Mono、UWP 等
.NET 标准(定义 1) - 一组用于基于 .NET 的运行时环境的标准 API 定义
.NET Standard(定义 2) - 一种基于 .NET 的库格式,受多种运行时环境支持,包括 .NET、Mono、UWP 等,它是PCL 格式。在 Visual Studio 中,可以通过进入项目属性并编辑目标框架,将 PCL 库转换为 .NET Standard 库。
我相信此资源可以回答您的大部分问题:
https://docs.microsoft.com/en-us/dotnet/articles/standard/library
The .NET Standard Library is a formal specification of .NET APIs that are intended to be available on all .NET runtimes. The motivation behind the Standard Library is establishing greater uniformity in the .NET ecosystem.
据我了解,其他库类型是特定于平台的,而 .NET 标准在某种程度上与平台无关。
如果您希望您的代码在不同平台上可用,那么 .NET 标准似乎是理想的选择,但请密切注意其他平台支持的 .NET 标准版本(请参阅 [=22= 中的 table ]).
希望对您有所帮助
标准版针对一组特定的 API 类似于 Android API 版本。 nuget 库只是元数据包,包含所有符合标准的库。
MSDEV 节目中的 Scott Hunter 很好地解释了这个概念。值得一试 - http://msdevshow.com/2016/07/dot-net-core-with-scott-hunter/
这边的文档确实比较混乱,但是大致可以这样理解:
PCL:针对一组平台的库(具有这些平台的 API 的 'least common denominator')。所以在写 PCL 时,你是说我想针对平台 A、B、C
.NET 标准:一组 'standard' API 而不是一个平台。所以基本上你不关心平台,只关心标准(版本 1.3、1.6 ...),你的代码将在支持它的所有平台上运行。
- .NET core这里不要混淆,是.NET framework的'another version'。 .NET 标准将跨运行时工作(.NET 框架、.NET 核心、Mono)
所以我想 .NET 标准是可行的方式:)
来自 Samuel Englard (https://github.com/dotnet/corefx/issues/973#issuecomment-249582799):
.NET DLLs are formatted according to ECMA-335 (Better known as the Common Language Infrastructure). This format is true across all platforms we call .NET; Full Framework, Core, Xamarin, Mono, Silverlight, etc.
The reason you couldn't use a DLL compiled against one platform with another was that the format didn't specify APIs (generally speaking). So while they could all read the DLL you'd run into issues of class XYZ being in namespace A.B.C on one platform and in namespace D.E.F on another, if it existed at all.
PCLs "solved" this by doing two things:
They used Type Forwarding so that even though you wrote your code expecting class XYZ in namespace A.B.C, it could be found on platforms that had it elsewhere. It limited what APIs you could use to the lowest common set shared by all the platforms you wanted.
Taking a PCL and converting it to a .NET Standard project is not a recompile because of output format but because of the meta data included (Type Forwarding particularly).
所以,我认为 .NET Standard 库本质上与 PCL 库没有什么不同,除了它们在不同的标准化 API 集之上放置了一个层,并且这些 API 可以实现不同的指针(类型转发)。
.NET Core 当然是一个运行时环境,但我认为它与 .NET Standard 非常接近。除了实现 .NET Standard API 之外,我认为它与它没有任何特殊关系。
In my mind, it is generally better to target a .NET Standard Class library because this will be compatible across multiple platforms。例如,如果您以 .NET Core 为目标,则无法在 UWP 中引用此程序集类型。你会看到这个:
但是,如果您在纯 .NET Core 环境中工作,您可能会发现有特定于 .NET Core 运行时环境的可用 API,因此有必要直接以 .NET Core 为目标。
请看这个词汇表: https://github.com/dotnet/corefx/blob/master/Documentation/project-docs/glossary.md