This is the 26th day of my participation in the August Text Challenge.More challenges in August

To understand the history and evolution, we need to understand the concepts of.NET Framwork,.NET, and.NET Stander. .NET stands for cross-platform framework. It has been called.NET since.NET 5, instead of.net Core. We’ll leave.net Core behind because there are so many names to avoid confusion.

.NET Framework

In the future, the.NET Framework may be a thing of the past, but there are still many places to use it. This system should be very familiar to the old coder of C#, and the new one should not have to work hard to learn.

The.net Framework is a technology that enables the generation and running of Windows applications and Web services.

The.NET Framework includes the Common Language Runtime (CLR) and.net Framework class libraries. The common Language runtime is the foundation of the.NET Framework. Think of the runtime as an agent that manages code as it executes, provides core services such as memory management, thread management, and remoting, and also enforces strict type safety and other forms of code accuracy that improve safety and reliability.

.Net

.NET evolved from.NET Core, with a lot of performance and architecture improvements at the bottom, and application apis and usage improvements at the top. NET Framework is mostly the same.

.NET is a free open source development platform for building a wide variety of applications, no matter what type of application you are building (Web, API, desktop…). The code and project files look the same. Access to the same runtime, API, and language functions for each application.

NET is open source, under the MIT and Apache 2 licenses. .net is a project of the.NET Foundation. Microsoft supports.net on Windows, macOS, and Linux. It is regularly updated to ensure safety and quality. .net supports three programming languages: C#, F#, and Visual Basic.

.NET Standard

.NET Standard is a set of formal.NET API specifications for multiple.NET implementations. The motivation behind.net Standard was to improve consistency in the.NET ecosystem. However,.NET 5 takes a different approach to establishing consistency, a new approach that in many cases does not require.NET Standard.

So.net Standard is a.NET Api specification, not an implementation. Its purpose is to improve.NET consistency, which can be achieved using the.NET Standard specification whenever the framework supports it. But! .NET 5 takes a different approach to establishing consistency, which means that.NET 5 starts to transition to the.NET framework if you only use the.NET framework, but support.net Standard! .net Standard is still needed for libraries that can be used by multiple.NET implementations. For example, internal libraries that are used on both the.NET Framework and.NET need to comply with the.NET Standard specification, so that both frameworks can work, but see the.NET Standard version support. == You can choose different support frameworks when creating the class library.

Various.NET implementations target specific versions of.net Standard. Each.NET implementation release publishes the highest VERSION of.NET Standard that it supports, and this declaration implies that it also supports previous releases.

An example

1. Create one. NET Standard class library, add a simple test method.

Public class NetStandardTest {public static void PrintLocation() {// Prints the FileStream path Console.WriteLine(typeof(FileStream).Assembly.Location); // Print NetStandardTest path console. WriteLine(typeof(NetStandardTest).assembly.location); }}Copy the code

We added two lines of print code to the test method. The main is to print the FileStream path while we create it. The NET Standard class library is 2.0, because we are going to create a console for the.NET Framework that does not support 2.1.

Net 5,.NET Framework 4.6.1 console application

Create two console projects and call the inner library method in the main method.

static void Main(string[] args)
{
    NetStandardTest.PrintLocation();

    Console.ReadKey();
}
Copy the code

The solution structure is as follows

3. Operation analysis

From the results we see the same thing. NET Standard library, reference in different frameworks, call the same FileStream address is different. We then locate FileStream in the.NET Standard class library surface F12 to see the assembly below

Let’s compare the three addresses side by side:

C: \ Program Files\dotnet\shared\Microsoft.NET Core App \ 5.0.8 \ System. Private. The CoreLib. DLL C:\Windows\Microsoft.NET \ Framework \ v4.0.30319 \ mscorlib. DLL C: \ Users \ \ Administrator \. Nuget \ packages \ netstandard library \ 2.0.3 \ build \ netstandard2.0 \ ref \ netstandard DLLCopy the code

Let’s decomcompile the three DLLS with DNSpy, go to FileStream, and look at the code with one of the BeginRead methods.

  • .net standard

  • .net framework

  • .net 5

As you can see from the comparison of the above three results,.net Standard has no implementation, only defines methods, that is, defines a standard that says what is in my class. Call time and then according to the framework we currently use to find the implementation of the corresponding framework. This is why.net Standard can reference multiple frameworks, and why 2.1 cannot be used by the.NET Framework, because it does not implement the apis added in 2.1. As to why we call the DLL of.NET Standard is transferred to the DLL of the corresponding framework, this is the technology of transferring the Type of the assembly by using Type Forwarding method called “Shim”, which is an important means to realize the cross-platform reuse of the assembly. About the gasket technology may have a look this article www.cnblogs.com/artech/p/ho… .

Since then, we have basically figured out how a few concepts and experiences have evolved. We will probably not use.net Standard much in the future, and we will use.net libraries as we continue to upgrade. We will not have to understand so many concepts and technologies, but we can understand that these are the products of transition iterations.