📜 ⬆️ ⬇️

Is the .NET Standard Library an adequate standard?

Whenever deviations appear in the current process, the following questions should be asked: “Did this happen because we didn’t have a standard? Did it happen because we didn’t follow the standard? Was it because the standard was not adequate? ”
Masaaki Imai (author of the Kaizen concept)

image

Cross-platform - one of the main requirements for the application on the market. Most of the modern programming languages ​​are cross-platform, however, in almost all languages, the developer is faced with the problem of compatibility of its software with a particular system. You have to compile your project for a specific operating system or develop a project for the execution environment of the interpreted language.

The .NET runtime allows you to develop cross-platform software using an intermediate code (byte code). .NET seems to be the best, in my opinion, solution for developing cross-platform software. However, like all others, this solution has its drawbacks. They are intended to eliminate. NET Standard.

How it was


Consider several .NET platforms. First, the .NET Framework is available only under Windows; you cannot run the runtime on other operating systems. Secondly, Mono / Xamarin is a truly cross-platform solution that supports Mac, iOS, Android. Among the shortcomings is the lack of full compatibility with the .NET Framework, as a result of which it is necessary to cut pieces of code from the project when porting to Mono / Xamarin. Another platform that appeared quite recently is .NET Core. It allows you to develop and run server cross-platform software for Windows, Linux, Mac, Docker.
')
Even with a large variety and coverage of operating systems, the program being developed may not be cross-platform, since platforms themselves are not fully compatible. There is a solution - we are developing a fully compatible kernel with all platforms and appending the missing parts. How to determine what is compatible and what is not? It remains only to spend time studying the documentation and APIs of these platforms.

Portable Class Library - Ancestor of .Net Standard Library


Portable Class Library (PCL) is a tool for developing a cross-platform library. When you create a project, you must select a list of platforms and begin development. Initially, PCL only supported Windows and Windows Phone. Soon, Microsoft acquired Xamarin, which immediately brought Xamarin support to PCL. As we develop .NET Core, support for this platform also appeared in PCL. Platforms are getting bigger - hence PCL, like the intersection of platforms, is getting smaller. Microsoft decided to offer an alternative solution.

New .NET Standard Library Platform


Microsoft is adding a new .NET Standard Library platform. My first thought: “now you need to read more documentation so that the project works on this platform too”. As it turned out, it is not. The .NET Standard Library is a formal set of common interface specifications for other platforms: .NET Core, .NET Framework, Mono / Xamarin, and others. Libraries conforming to the .NET Standard specifications can be used on various .NET platforms. In fact, Standard guarantees the possibility of using libraries in different execution environments; it brings universality, which was so lacking, into the .NET ecosystem.

.NET Standard changes the architecture of applications, it is located as a layer between the common infrastructure. NET and end platforms.

image

Highlighting the cross-platform application core has become much easier. Enough for the kernel to build under Standard. Also, you can use any other .NET Standard libraries in this kernel. New layer is the curator for future platforms. New platforms will have to comply with .NET Standard, and not vice versa, as was the case with PCL.

Own Standard for each platform


The .NET Standard Library is distinguished by version — each version has full compatibility with the next one (which is not the case with PCL). There is no backward compatibility. If you choose a higher version, more APIs will be available for library development. However, this means that fewer platforms will support the library being developed. Below is a table of different versions of .NET Standard (the table is compiled for the release version of .NET Standard).

Target Platform NameAlias
.NET Standardnetstandard1.01.11.21.31.41.51.6
.NET Corenetcoreapp1.0
.NET Frameworknet4.54.5.2
4.5.1
4.64.6.14.6.24.6.3
Universal windows platformuap10.0
Windowswin8.08.1
Windows phonewpa8.1
Windows phone silverlightwp8.1
8.0
Mono / Xamarin Platforms*
Mono*

The first line contains the version numbers of the .NET Standard Library. Each next line contains a platform and a version that can use a library written using the corresponding Standard. The arrows indicate the compatibility of this Standard version with the next cell in the same row.

Examples:

  1. If the library meets the specifications of .NET Standard 1.3, then it can be used only on platforms: .NET Framework 4.6 (and newer), .NET Core, Universal Windows Platform 10 (UWP) and Mono / Xamarin.
  2. If a library is written under Standard 1.3, then it can use other libraries that are written using Standard versions: 1.0, 1.1, 1.2, 1.3.

Understanding the .NET Standard Library


The .NET Standard Library can be represented as abstract sets, each of which will contain the previous one and add something different, covering more code of the .NET platforms. Accordingly, their size will increase as the version number increases.

image

With each new version, the functionality of the application core will grow, however, many features of “full-fledged” platforms will not be available. Let's look at the images of other sets: .NET Framework, .NET Core, Mono / Xamarin:

imageimageimage

.NET Standard of the same version covers the identical set of code of these platforms. And it is entirely inside their intersection. The application core will be located inside the center circle. The application itself is better divided into three parts for the implementation of support for other platforms. Thus, the finished product will work simultaneously on three platforms and on several operating systems.

imageimage

Advantages of using .NET Standard Library:



Cons of using the .NET Standard Library:



Conclusion


The .NET Standard Library is a good replacement for the inconvenient Portable Class Library. Standard Library is much better in terms of cross-platform. Now you can easily select a cross-platform application core or develop a cross-platform library that meets the specifications of the .NET Standard. Then write the necessary interfaces for the necessary operating systems and get the finished product.

Source: https://habr.com/ru/post/314588/


All Articles