且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

.Net Core,Portable,Standard,Compact,UWP和PCL之间的区别?

更新时间:2022-11-05 16:33:04

我将首先回答您的第二个问题:

I'll answer your second question first:

我有一个针对.Net 2.0,.Net 4.5和UWP的库.针对UWP,需要创建一个新的VS项目并链接所有现有文件,这是一个巨大的痛苦.现在有人告诉我它不适用于PCL,而且从它的声音来看,我必须再次对.Net Standard执行此操作!?)

I have a library that targets .Net 2.0, .Net 4.5, and UWP. Targeting UWP required creating a new VS project and linking all the existing files, which is a huge pain. Now someone is telling me it doesn't work for PCL, and from the sound of it I have to do it AGAIN for .Net Standard!?)

如果我想编写一个对尽可能多的读者可用的库,我需要使用其中的一个(或多个)?

If I want to write a library that's usable to as large an audience as possible, which one (or more than one) of these do I need to use?

简短的回答:您应该定位netstandard.使用具有所有功能的最低版本您需要的API.您可以使用 API端口之类的工具来

Short answer: you should target netstandard. Use the lowest version that has all the APIs you need. You can use a tool like API Port to check your existing project for compatibility with a given netstandard version.

不幸的是,这种方法将遗留较旧的平台,在您的情况下是.NET 2.0.如果需要维护.NET 2.0支持,那么您将需要一个单独的项目(带有链接文件)来构建一个单独的.NET 2.0程序集.

Unfortunately, this approach will leave behind older platforms, in your case, .NET 2.0. If maintaining .NET 2.0 support is necessary, then you'll need a separate project (with linked files) to build a separate .NET 2.0 assembly.

详细信息...

有什么区别!?

What's the difference!?

  • .Net标准(netstandard)-这是新的跨平台BCL API.从某种意义上说,它只是一个API定义,而不是一个实现,因此它是一个标准".想法是您可以将库编译为该API(的一个版本),并且它将在支持该版本的任何平台上运行.
  • .Net Core -您可以将其视为netstandard的参考实现(有一些额外的补充).它是该API的跨平台实现. UI和其他框架可能基于它构建,但是就目前而言,它唯一确定的立足点是ASP.NET Core的选择平台. [旁注:由于历史原因,.NET Core"与netcore NuGet目标完全不同.当您处于NuGet上下文中时, netcore表示"Windows 8/8.1/10] .
  • .Net Portable 便携式类库-便携式类库(PCL)是提供跨平台API的最不常用的方法.它们涵盖了范围广泛的目标平台,但是它们不完整,并且不能满足未来需求.它们实际上已由netstandard代替.
  • .Net Compact -这是一个完全不同的.NET框架,具有自己的独特API.它与任何其他框架,PCL或netstandard版本完全不兼容;因此,它比其他任何平台都难以支持.但是,它仍然在内存紧张的设备上使用.
  • 通用Windows平台-这是Win10时代Windows Phone和桌面之间的API合并,允许为两个平台编写Windows Store应用/库.基本上已由netstandard代替.
    • .Net Standard (netstandard) - this is the new cross-platform BCL API. It's a "standard" in the sense that it's just an API definition and not an implementation. The idea is that you can compile your library to (a version of) this API and it will run on any platform that supports that version.
    • .Net Core - you can think of this as a reference implementation of netstandard (with a few extra bits). It is a cross-platform implementation of that API. It is possible that UIs and other frameworks may build on it, but for now its only sure foothold is acting as the platform of choice for ASP.NET Core. [Side note: for historical reasons, ".NET Core" is completely different than the netcore NuGet target; when you're in a NuGet context, netcore means "Windows 8/8.1/10"].
    • .Net Portable and Portable Class Libraries - Portable Class Libraries (PCLs) are a least-common-denominator approach to providing a cross-platform API. They cover a wide range of target platforms, but they are incomplete and not future-proof. They have essentially been replaced by netstandard.
    • .Net Compact - This is a completely different .NET framework with its own unique API. It is completely incompatible with any other framework, PCL, or netstandard version; as such, it is much more difficult to support than any other platform. However, it is still used on devices with tight memory constraints.
    • Universal Windows Platform - This was a Win10-era merging of the API between Windows Phone and desktop, allowing Windows Store apps/libraries to be written for both platforms. This has essentially been replaced by netstandard.