News
.NET Standard 2.0 Is Finalized for Consistent API Usage
The open source .NET Standard 2.0 project was finalized today, providing a formal spec for .NET APIs that should be available to developers working with all .NET implementations.
With finalization, developers can now create .NET Standard 2.0 libraries and NuGet packages, Microsoft program manager Immo Landwerth announced in a GitHub issue.
The .NET Standard project for Visual Studio 2017, hosted on a GitHub site belonging to the .NET Foundation, was announced last September. Microsoft said .NET Standard will replace Portable Class Libraries (PCLs) as the de-facto tooling story used by developers for building multi-platform .NET libraries.
".NET Standard solves the code sharing problem for .NET developers across all platforms by bringing all the APIs that you expect and love across the environments that you need: desktop applications, mobile apps & games, and cloud services," Microsoft said in a huge blog post (with nearly 200 comments) explaining the standard in detail.
Apparently facing developer confusion about exactly what .NET Standard is for, Microsoft has devoted some guidance to explaining it, even pointing to an analogy written by David Fowler.
Furthermore, Microsoft explains the difference between the .NET Standard and .NET Core in a FAQ. "NET Standard is a specification that covers which APIs a .NET platform has to implement," it says. ".NET Core is a concrete .NET platform and implements the .NET Standard."
Other developers took a stab at describing it in a Hacker News post. "Conceptually, I think of it in terms of browsers and browser standards," said one commenter identifying as a Microsoft .NET team member. "The relationship between .NET Standard and the various .NET platforms (.NET Core, .NET Framework, Mono, Xamarin, UWP, etc.) is similar to HTML specifications (e.g. https://www.w3.org/TR/html5/) and individual browsers. Newer HTML features are available on newer browsers, and some browser feature implementation is contextualized (e.g. some web features don't make sense on a mobile phone browser)."
The new version 2.0 standard introduces no breaking changes from the prior version 1.6, but Microsoft said it was given a major revision number because it's so different from the previous release. The number of differences is so great that the GitHub page created to detail those differences wouldn't display the list, saying the file was too big (the gigantic diff file can be viewed in raw format). The project FAQ said 2.0 more than doubled the API surface and added a compat shim that lets developers reference existing binaries, even if such binaries are not built against .NET Standard or PCLs.
In fact, Landwerth said in his post, the number of available APIs jumped from about 13,000 to 32,000. Regarding the .NET Framework compatibility mode, he said: "The vast majority of NuGet packages are currently still targeting .NET Framework. Many projects are currently blocked from moving to .NET Standard because not all their dependencies are targeting .NET Standard yet. That's why we added a compatibility mode that allows .NET Standard projects to depend on .NET Framework libraries as if they were compiled for .NET Standard.
"Of course, this may not work in all cases (for instance, if the .NET Framework binaries uses WPF), but we found that 70 percent of all NuGet packages on nuget.org are API compatible with .NET Standard 2.0, so in practice it unblocks many projects," he continued.
Visual Studio 2017 15.3 should be used to create .NET Standard 2.0 libraries.
About the Author
David Ramel is an editor and writer for Converge360.