我听说过
- .Net核心
- .Net 便携版
- .Net 标准
- .Net Compact
- 通用 Windows 平台
- 可移植类库
所有这些都向我解释为 “允许您针对多个平台的完整 .Net 的一个子集”。所以我的问题是
- 有什么区别!?
- 如果我想编写一个可供尽可能多的受众使用的库,我需要使用其中的哪一个(或多个)?
(我的具体情况:我的 a library 以 .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
为目标。使用 lowest version拥有您需要的所有 API。您可以使用类似 API Port 的工具至 check your existing project for compatibility with a given netstandard
version .
不幸的是,这种方法将落后于较旧的平台,在您的例子中是 .NET 2.0。如果有必要维护 .NET 2.0 支持,那么您将需要一个单独的项目(带有链接文件)来构建一个单独的 .NET 2.0 程序集。
关于细节...
What's the difference!?
- .Net Standard (
netstandard
) - 这是新的跨平台 BCL API。它是一个“标准”,因为它只是一个 API 定义而不是一个实现。这个想法是,您可以将您的库编译为该 API 的(一个版本),它将在支持该版本的任何平台上运行。 - .Net Core - 您可以将其视为
netstandard
的引用实现(带有一些额外的位)。它是该 API 的跨平台实现。 UI 和其他框架可能基于它构建,但目前它唯一确定的立足点是充当 ASP.NET Core 的首选平台。 [旁注:由于历史原因,“.NET Core”与netcore
NuGet 目标完全不同;当您处于 NuGet 上下文中时,netcore
means "Windows 8/8.1/10"] . - .Net Portable 和 Portable Class Libraries - Portable Class Libraries (PCL) 是提供跨平台 API 的最小公分母方法。他们涵盖了 wide range of target platforms ,但它们是不完整的,也不是面向 future 的。它们基本上已被
netstandard
取代。 - .Net Compact - 这是一个完全不同的 .NET 框架,具有自己独特的 API。它与任何其他框架、PCL 或
netstandard
版本完全不兼容;因此,它比任何其他平台都更难支持。但是,它仍然用于具有严格内存限制的设备。 - 通用 Windows 平台 - 这是 Windows Phone 和桌面之间 API 的 Win10 时代合并,允许为两个平台编写 Windows 应用商店应用程序/库。这基本上已被
netstandard
取代。
关于c# - .Net Core、Portable、Standard、Compact、UWP 和 PCL 之间的区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40514546/