更新时间: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!?
netstandard
)-这是新的跨平台BCL API.从某种意义上说,它只是一个API定义,而不是一个实现,因此它是一个标准".想法是您可以将库编译为该API(的一个版本),并且它将在支持该版本的任何平台上运行.netstandard
的参考实现(有一些额外的补充).它是该API的跨平台实现. UI和其他框架可能基于它构建,但是就目前而言,它唯一确定的立足点是ASP.NET Core的选择平台. [旁注:由于历史原因,.NET Core"与netcore
NuGet目标完全不同.当您处于NuGet上下文中时, netcore
表示"Windows 8/8.1/10] .netstandard
代替.netstandard
版本完全不兼容;因此,它比其他任何平台都难以支持.但是,它仍然在内存紧张的设备上使用.netstandard
代替.
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.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"].netstandard
.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.netstandard
.