.NET 标准、.NET 核心、PCL [英] .NET Standard, .NET Core, PCL

查看:28
本文介绍了.NET 标准、.NET 核心、PCL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.NET Standard 一直是一个令人困惑的概念.标准 .NET 库格式的想法听起来很棒.但是,具体是什么还不清楚.Visual Studio 中现在有 .NET Core 和 .NET Standard 类库项目模板,以及旧的 PCL 项目.我还发现,如果您进入项目的设置,您可以将现有的 PCL 库切换到 .NET Standard.不清楚 .NET 标准是否是一个库?或者DLL格式.

我要问的基本问题是我们应该针对哪种类型的库?我主要是为 Xamarin 项目执行此操作,但如果我们可以与其他人共享这些库,那就太好了平台,尤其是 .NET Core 和 UWP.令人困惑的是,微软为什么同时推出了两种看似相同的类库类型:.NET Core 和 .NET Standard.

定义

NET Core - 基于 .NET 的运行时环境,符合 .NET Standard API 定义.

PCL - 一种基于 .NET 的库格式,受多种运行时环境支持,包括 .NET、Mono、UWP 等

.NET Standard(定义 1) - 基于 .NET 的运行时环境的一组标准 API 定义

.NET Standard(定义 2) - 一种基于 .NET 的库格式,受多个运行时环境支持,包括 .NET、Mono、UWP 等,它是 PCL 格式的延续.在 Visual Studio 中,可以通过进入项目的属性并编辑目标框架将 PCL 库转换为 .NET Standard 库.

解决方案

This from Samuel Englad (

但是,如果您在纯 .NET Core 环境中工作,您可能会发现有特定于 .NET Core 运行时环境的可用 API,因此有必要以 .NET Core 为目标直接.

请参阅此词汇表:https://github.com/dotnet/corefx/blob/master/Documentation/project-docs/glossary.md

.NET Standard has been a confusing concept. The idea of a standard .NET library format sounds great. But, it's not clear what it is exactly. There are now .NET Core, and .NET Standard Class Library project templates in Visual Studio, as well as the old PCL projects. I also found that if you go in to the settings for the project, you can switch an existing PCL library over to .NET Standard. It's not clear if .NET standard is a library? Or a DLL format.

The basic question I'm asking is which type of library should we be targeting? I'm mainly doing this for Xamarin projects, but it would be great if we could share these libraries with other platforms, especially .NET Core, and UWP. It's confusing as to why Microsoft brought out two seemingly identical Class Library types at the same time: .NET Core, and .NET Standard.

Definitions

NET Core - a .NET based runtime environment which conforms to the .NET Standard API definition.

PCL - a .NET based library format supported by several runtime environments including .NET, Mono, UWP, and so on

.NET Standard (Definition 1) - A set of standard API definitions for .NET based runtime environments

.NET Standard (Definition 2) - a .NET based library format supported by several runtime environments including .NET, Mono, UWP, and so on which is a continuation of the PCL format. In Visual Studio, a PCL library can be converted to a .NET Standard library by going in to the properties of the project and editing the target framework.

解决方案

This from 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).

So, I think that essentially .NET Standard libraries are no different than PCL libraries except for the fact that they put a layer over the top of a different standardized set of APIs, and those APIs may implement different pointers (Type forwarding).

.NET Core is of course a runtime environment, but I think that it is just very closely aligned with .NET Standard. I don't think that it has any special relationship to it other than the fact that it implements the .NET Standard APIs.

In my mind, it is generally better to target a .NET Standard Class library because this will be compatible across multiple platforms. If you target .NET Core, this assembly type cannot be referenced in UWP for example. You will see this:

However, if you are working in a pure .NET Core environment, you may find that there are APIs available that are specific to the .NET Core runtime environment, and therefore it will be necessary to target .NET Core directly.

Please see this glossary: https://github.com/dotnet/corefx/blob/master/Documentation/project-docs/glossary.md

这篇关于.NET 标准、.NET 核心、PCL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆