微软为了统一微软平台,造就了.netStandard,不管之前的Framework还是最新的.netCore都必须支持.netStandard标准来统一各个平台的开发api。
以下是之前的微软各个平台构成,这种分叉对于开发人员为多个.NET平台编写代码构成了巨大的问题,因为没有一个统一的类库来定位:
目前有三种主要的.NET平台,这意味着您必须掌握三种不同的基类库,以便编写可在其中运行的所有代码。由于行业现在比起.NET最初创建的时候更加多样化,如果我们定义一个标准,那将极大简化开发过程并且规范各个平台开发的一致性。
以下是.netStandard之后的微软平台构成:
从图可看出三大平台的底层都是.netStandard来支撑,对于开发人员来说,这意味着他们只需要掌握一个基类库。面向.NET Standard的库将能够在所有.NET平台上运行。平台提供商不必猜测他们需要提供哪些API才能使用NuGet上可用的库。
我们需要.NET标准有两个原因:
1.Driving force for consistency .We want to have an agreed upon set of required APIs that all .NET platforms have to implement in order to gain access to the .NET library ecosystem.
2.Foundation for great cross-platform tooling .We want a simplified tooling experience that allows you to target the commonality of all .NET platforms by choosing a single version number.
.NET Standard 2.0有什么新功能?
当NET Core 1.0时,微软还引入了.NET Standard。有多个版本的.NET标准,以表示所有当前平台的API可用性。下表显示了现有平台的哪个版本与给定版本的.NET Standard兼容情况:
箭头表示该平台支持更高版本的.NET Standard。例如,.NET Core 1.0支持.NET Standard 1.6版,这就是为什么有较低版本1.0 - 1.5的箭头指向的原因。
从图可知微软在.NET Framework4.5开始执行.NET Standard1.1标准(换句话说也许是.NET Standard1.1以.NET Framework为标准制定,毕竟.NET Framework4.5的时候还没有出现.NET Standard标准),这样的话那以后就可以开发1.1版本的.NET Standard作为中间间供.NET Framework引用,也可以供支持了1.1标准的其他平台的引用(例如.NET Core或者未来微软开发的新的平台,只要支持.NET Standard1.1的即可)。这样极大的统一了微软各个平台代码的共享。
官方介绍
You can use this table to understand what the highest version of .NET Standard is that you can target, based on which .NET platforms you intend to run on.For instance, if you want to run on .NET Framework 4.5 and .NET Core 1.0, you can at most target .NET Standard 1.1.(您可以使用此表来决定您要运行的.NET平台来可以定位的最高版本的.NET Standard。(官方这段话大意是如果开发例如.NET Framework4.5 和 .NET Core 1.0上运行的程序,那最多只能开发.NET Standard1.1版本的程序集)
From a library targeting .NET Standard you’ll be able to reference two kinds of other libraries:
- .NET Standard, if their version is lower or equal to the version you’re targeting.
- Portable Class Libraries, if their profile can be mapped to a .NET Standard version and that version is lower or equal to the version you’re targeting.
(以上大意是如果你开发了.NET Standard程序集,那你可以引用两种两种类型的类库:
1.引用不大于当前.NET Standard 版本的.NET Standard
2.引用PCL,前提是其描述文件对应到不大于您当前 .NET Standard版本)
The following improvements are included in .NET Core 2.0 Preview 1:
- Massive API increase (>100%) relative to .NET Core 1.x.
- Support for .NET Standard 2.0.
- Support for referencing .NET Framework libraries and NuGet packages.
- Support for Visual Basic.
以上大意是:
.NET Core 2.0 Preview预览版包括四点改进:
- 相对于Core1.1增加大量api
- 支持.NET Standard2.0
- 支持引用.NET Framework和NuGet的包
- 支持VB语言
.NET Standard 2.0
.NET Standard allows sharing code, binaries and skills across all flavors of .NET, including .NET Framework, .NET Core, Xamarin, Unity, and UWP(以上大意是开发的.net Standard2.0类库可以在微软旗下任意平台引用,例如在Framework和Xamarin和Unity或者UWP项目下都可以引用同一个.NET Standard类库)
Here is what’s new with .NET Standard 2.0:
- Has a much bigger API surface. It’s extended to cover the intersection between
.NET Framework and Xamarin. This also makes .NET Core 2.0 much bigger as it
implements .NET Standard 2.0. The total number of APIs added to .NET Standard
is ~20,000.
- Can reference existing .NET Framework libraries. The best thing is:
no recompile required, so this includes existing NuGet packages. Of course,
this will only work if the consumed libraries use APIs that exist in .NET
Standard. However, our extensive API surface results in 70% of all NuGet
packages to be API compatible with .NET Standard 2.0.
(以上大意是 .NET Standard 2.0两个新功能:
- 支持更多的api
- 可以引用现有.NET Framework,前提是.NET Framework使用了在.NET Standard 存在的Api才有效)
Visual Studio 2017 Improvements
Visual Studio 2017 continues to use .NET Core 1.x by default.You need to install the .NET Core SDK 2.0 Preview 1 to get .NET Core 2.0 support.(以上大意是VS17默认情况下继续使用Core1.X 的版本,除非你安装2.0预览版得到2.0支持。.NET Core2.0预览版下载地址https://www.microsoft.com/net/core/preview#windowscmd)