简体   繁体   English

NuGet软件包应支持哪些.NET版本以最大化其可用性和功能?

[英]Which .NET versions should be supported by NuGet packages to maximize their availability and functionality?

TL;DR: TL; DR:

  • Given: I wrote a library with relatively portable functionality (for example, Left.Pad.©.dll ). 鉴于:我编写了一个具有相对可移植功能的库(例如, Left.Pad.©.dll )。 I want to make it available though NuGet. 我想通过NuGet使它可用。

  • Requirement: If somebody wants to use my library on any version of any platform on any version of any operating system with any updates installed by writing code in any IDE or any code editor, they should be able to do it. 要求:如果有人想用我的图书馆在任何平台上的任何操作系统,在任何 IDE或任何代码编辑器编写代码安装任何更新的任何版本的任何版本,他们应该能够做到这一点。

  • Question: What is the minimum set of NuGet target frameworks to achieve that? 问题:实现该目标最低 NuGet 目标框架集是什么?

  • Bonus question: If there're any "dead" frameworks which shouldn't be targeted, or something else which should be taken into consideration when choosing target frameworks, you can mention it too. 额外的问题:如果有任何不应该作为目标的“死”框架,或者在选择目标框架时应该考虑的其他东西,您也可以提及。


Thoughts (old version): 想法(旧版本):

NuGet packages support multiple .NET Framework versions and profiles , for example, a package can provide net20, net30, net35, net40, net45, sl3, sl4, sl5 etc. versions. NuGet软件包支持多个.NET Framework版本和配置文件 ,例如,一个软件包可以提供net20,net30,net35,net40,net45,sl3,sl4,sl5等版本。 However, assuming there aren't always differences in the functionality of a package , providing a lot of versions would be a waste of build time and package size and cause unnecessary complexity. 但是,假设包的功能并不总是存在差异 ,提供很多版本会浪费构建时间和包大小,并导致不必要的复杂性。 On the other hand, providing a package just for the lowest supported Framework version could cause missing functionality, for example .NET 4 supports in-process side-by-side execution of multiple CLR versions, but previous versions don't, so this feature will be lost if just a version for .NET 3.5 is provided (I'm not sure; I've never used it and don't know the details). 另一方面,仅为受支持的最低Framework版本提供软件包可能会导致功能丢失,例如.NET 4支持在进程中并行执行多个CLR版本,但以前的版本不支持,因此此功能如果仅提供.NET 3.5版本,则将丢失(我不确定;我从未使用过它,也不知道详细信息)。 If a PCL version is provided, the logic is simple I assume: just exclude versions which PCL covers. 如果提供了PCL版本,则我认为逻辑很简单:仅排除PCL涵盖的版本。

At the moment of writing, the easiest way is to create a .NET Standard 1.1 project. 在撰写本文时,最简单的方法是创建一个.NET Standard 1.1项目。 It supports 它支持

  • .NET Core 1.0 and higher .NET Core 1.0及更高版本
  • .NET Framework 4.5 and higher .NET Framework 4.5及更高版本
  • Mono, Xamarin, Windows Phone and more... 单声道,Xamarin,Windows手机以及更多...

So pretty much all of the modern platforms. 几乎所有的现代平台。 If you want to support older platforms, ex. 如果您想支持较旧的平台,例如。 .NET Framework 3.0, add this as a separate "folder" in NuGet. .NET Framework 3.0,请将其添加为NuGet中的单独“文件夹”。 This way, newer .NET Core applications can still use your package. 这样,较新的.NET Core应用程序仍可以使用您的程序包。


More information 更多信息

.NET Standard acts a replacement for PCL . .NET Standard代替了PCL The lowest .NET Framework you can target with PCL is 4.0, which isn't much lower than 4.5 with .NET Standard 1.1 (thus won't make your package much more accessible). 您可以使用PCL定位的最低.NET Framework为4.0,这与.NET Standard 1.1的4.5相比并不低(因此不会使您的程序包更易于访问)。

PCL also doesn't seem to support .NET Core, while .NET Standard nearly supports all platforms: PCL似乎也不支持.NET Core,而.NET Standard几乎支持所有平台: .NET标准支持表

Also note that according to Microsoft, only .NET Framework 3.5 SP1 and .NET Framework >= 4.5.2 are currently supported . 还要注意, 根据Microsoft,目前仅支持.NET Framework 3.5 SP1和.NET Framework> = 4.5.2 All other .NET Framework versions already reached end of life and won't get any updates. 所有其他.NET Framework版本已经到期,并且不会获得任何更新。 Windows Phone is also dead and Silverlight isn't getting anywhere too. Windows Phone也已经死了,Silverlight也无法使用。

As @Lex Li mentioned in the comments, .NET Standard 1.1 has a very low API surface, which means there are maybe some important APIs missing. 正如@Lex Li在评论中提到的那样,.NET Standard 1.1的API界面非常低,这意味着可能缺少一些重要的API。 Because of that, most NuGet packages use a higher .NET Standard version. 因此,大多数NuGet软件包都使用更高的.NET Standard版本。 It is recommended to use the lowest .NET Standard version possible. 建议使用最低的.NET Standard版本。

So with .NET Standard 1.1, you will support a huge majority of the modern frameworks. 因此,使用.NET Standard 1.1,您将支持绝大多数现代框架。 Sadly, I couldn't find any .NET Framework distribution statistics... 可悲的是,我找不到任何.NET Framework分布统计信息...


If you really want to make your package available for every platform , take a look at the possible target platforms for NuGet . 如果您确实想使您的软件包可用于所有平台 ,请查看NuGet可能的目标平台 I think you need atleast net11 and netstandard1.0 , maybe add some Silverlight and .NET MicroFramework support... 我认为您需要至少net11netstandard1.0 ,也许添加一些Silverlight和.NET MicroFramework支持...

Solution of 2018 2018解决方案

Based on given asnwers and assuming no dependency on platform-specific technologies (like System.Drawing, ASP.NET or WPF; in which case just target the platform you can and be done with it): 基于给定的答案,并假设不依赖于特定于平台的技术(例如System.Drawing,ASP.NET或WPF;在这种情况下,仅针对您可以并且可以使用的平台):

  1. netstandard1.0netstandard2.0 Start with .NET Standard 1.0 and go up until you reach maximum functionality. netstandard1.0netstandard2.0从.NET Standard 1.0开始,直到达到最大功能为止。

    This should cover: 这应该包括:

    • .NET Framework 4.5 .NET Framework 4.5
    • .NET Core 1.0 .NET Core 1.0
    • Mono 4.6 单声道4.6
    • Xamarin.iOS 10.0 Xamarin.iOS 10.0
    • Xamarin.Android 7.0 Xamarin.Android 7.0
    • Windows Universal 10.0 Windows通用10.0
    • Windows non-Universal 8.0 (up to .NET Standard 1.2) Windows非通用8.0(最高.NET Standard 1.2)
    • Windows Phone 8.1 (up to .NET Standard 1.2) Windows Phone 8.1(最高.NET Standard 1.2)
    • Windows Phone Silverlight 8.0 (up to .NET Standard 1.0) Windows Phone Silverlight 8.0(最高.NET Standard 1.0)

    If you can't reasonably implement the library within the limits of relatively small .NET Standard 1.0–1.2, the last three points are likely to be excluded. 如果您不能在相对较小的.NET Standard 1.0–1.2的范围内合理地实现该库,则很可能会排除最后三点。 If you still need them, see points below. 如果仍然需要它们,请参阅以下几点。

    .NET Standard 1.5+ increases the requirements on the versions of the frameworks and operating systems, so multi-targeting .NET Standard versions may be required for maximum compatibility. .NET Standard 1.5+增加了对框架和操作系统版本的要求,因此可能需要多目标.NET Standard版本才能实现最大的兼容性。

  2. portable-net40+* The next major point is obsolete PCL. portable-net40+*下一个要点是过时的PCL。 Its .NET Framework 4.5+ versions aren't relevant as they're mostly covered by .NET Standard. 它的.NET Framework 4.5+版本不相关,因为它们主要由.NET Standard涵盖。 If you want to support Windows Phone 8 and non-Universal Windows Store 8, you should do it through PCL, unless you're limited by API, in which case you'll have to add platform-specific targets. 如果要支持Windows Phone 8和非通用Windows Store 8,则应通过PCL进行,除非受到API的限制,在这种情况下,您必须添加特定于平台的目标。

    If you don't need any of additional platforms and .NET Framework 4.0 provides some useful additional functionality over .NET 3.5, you can target it directly, not through PCL. 如果您不需要任何其他平台,并且.NET Framework 4.0通过.NET 3.5提供了一些有用的其他功能,则可以直接将其定位,而不是通过PCL。

    This should cover: 这应该包括:

    • .NET Framework 4.0 .NET Framework 4.0
    • Windows non-Universal 8.0 Windows非通用8.0
    • Windows Phone 8.0 Windows Phone 8.0
    • Windows Phone Silverlight 8.0 Windows Phone Silverlight 8.0
  3. net20net35 If you want to support ancient desktop Windows versions (like Windows XP) and unupdated more recent Windows versions (like Windows Vista+ with .NET 3.0+), you should add support for desktop .NET Framework targets directly. net20net35如果要支持net35桌面Windows版本(例如Windows XP)和未更新的较新Windows版本(例如带有.NET 3.0+的Windows Vista +),则应直接添加对桌面.NET Framework目标的支持。 Note that as of 2018-01-01, the lowest supported .NET is 3.5 SP1, so going lower than that is probably unnecessary and will likely limit API available to you too much with no real benefits. 请注意,自2018年1月1日起,支持的最低.NET是3.5 SP1,因此降低到最低水平可能是不必要的,并且可能会限制您太多可用的API,而没有真正的好处。

    This should cover: 这应该包括:

    • .NET Framework 2.0-3.5 .NET Framework 2.0-3.5
    • Windows XP Windows XP
  4. There're other platforms, namely Xamarin-specific ones, Tizen, .NET Micro etc. They can be accessed only by targeting them directly. 还有其他平台,即Xamarin特定的平台,Tizen,.NET Micro等。只能直接将其定位为目标才能访问它们。

    This should cover: 这应该包括:

    • Everything else 其他一切

TL;DR TL; DR

Something like netstandard1.1 + portable-net40+win8 + net35 covers every relevant platform. 诸如netstandard1.1 + netstandard1.1 portable-net40+win8 + net35涵盖了每个相关平台。

Solution of the future 未来的解决方案

When old .NET versions completely die, only .NET Standard should remain. 当旧的.NET版本完全消失时,仅应保留.NET Standard。 Well, unless Microsoft invents yet another cross-platform unification technology, like it already did with .NET, .NET PCL, .NET Standard... 好吧,除非微软发明了另一种跨平台的统一技术,就像.NET,.NET PCL,.NET Standard那样。

TL;DR TL; DR

Use the lowest netstandard you can. 使用可能的最低网络netstandard

You should target .net framework 2.0 and above. 您应该针对.net framework 2.0及更高版本。 The decision should be based on the platform the application will run in production. 该决定应基于应用程序将在生产环境中运行的平台。 .net 2.0 comes included in Windows 2008 server (SP2 and onward) and people still use it extensively in production. .net 2.0包含在Windows 2008服务器(SP2及更高版本)中,人们仍然在生产中广泛使用它。 Ref https://en.wikipedia.org/wiki/.NET_Framework 引用https://en.wikipedia.org/wiki/.NET_Framework

If you want it to be used not only on Windows - .NET Standard is the way to go. 如果您希望不仅在Windows上使用它-则需要使用.NET Standard。 Target latest as question of what libraries to use comes early in a project and is rarely revisited and new projects tend to use recent versions of frameworks and libraries. 由于要使用什么库的问题是在项目的早期出现的,因此很少针对最新问题,并且很少重新访问,新项目倾向于使用最新版本的框架和库。

You can find recent market shares of user devices based on internet usage easily. 您可以根据互联网使用情况轻松找到用户设备的最新市场份额。

See the numbers, pick platforms you want to reach and cross-reference it with which versions of .NET are available on them. 查看数字,选择要访问的平台,并与它们上可用的.NET版本进行交叉引用。

Targeting .Net Standard would give your nuget package the luxury of being employable in .NET framework ,.NET core, mono, Xamarin, Universal Windows Platform, and Windows Phone projects. 面向.Net Standard将为您的nuget包提供在.NET Framework,.NET core,mono,Xamarin,Universal Windows Platform和Windows Phone项目中使用的豪华体验。

See the following taken from this answer 请参阅此答案中的以下内容

.Net标准

To decide which version of .Net standard you should target use the following table: 要确定您应该定位的.Net标准版本,请使用下表:

.net标准支持表

Source . 来源

Looking at the above table I would recommend going with .Net standard 1.0 if you care about Windows Phone Silverlight or .Net standard 1.2 if you do not. 查看上表,如果您不关心Windows Phone Silverlight,建议您使用.Net标准1.0;如果您不关心Windows NT,则建议使用.Net标准1.2。

Also, as far as I noticed lots of people that chose .net core are actually using .net core 2.0 so you might want to create a seperate nuget version for them with .net standard 2.0. 另外,据我所知,很多选择.net core的人实际上是在使用.net core 2.0,因此您可能希望使用.net standard 2.0为他们创建一个单独的nuget版本。

About the second part of your question, even if a specific framework is dead that does not mean that it would go away instantly, it would be still used for several years before it is completely dead, simply moving to different options takes time. 关于问题的第二部分,即使一个特定的框架已经失效,这并不意味着它会立即消失,但在它完全失效之前,它仍将使用数年,仅转移至其他选项就需要时间。

Another thing that I would take into consideration is the common used libraries, like Masstransit , EPPlus , and the commonly used IOCs, etc.. I would take a general look on the frameworks supported by them and follow because many undergoing projects might be driven by such libraries. 我还要考虑的另一件事是常用的库,例如MasstransitEPPlus和常用的IOC等。我将对它们所支持的框架进行一般性的研究,并遵循它们,因为许多正在进行的项目可能是由这样的图书馆。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM