Since the birth of various .NET implementations and .NET Standard, there has been a lot of confusion regarding these topics in the development community. We will try to eliminate that confusion by explaining these topics in a simple and understandable way.
Let’s start chronologically, with .NET Framework.
The Importance of .NET Framework
.NET Framework is the original implementation of .NET which was developed by Microsoft in the early 2000s to build Web and Desktop applications for Windows. It allows us to write applications in C#, Visual Basic, and F#.
It is an execution environment that provides a variety of services to its running applications and also an extensive class library to write different kinds of applications.
.NET Framework consists of two major components:
- Common language runtime (CLR) – which handles the execution of applications
- Base Class Library (BCL) – which provides a library of tested and reusable code that developers can use in their applications
The code written in any .NET supported language is compiled into a special language called Intermediate Language (IL) and stored in assembly files with a .dll or .exe file extension. When an application runs, the CLR takes the assembly and turns it into machine code through a process called just-in-time (JIT) compilation.
The .NET Framework provides many services to its running applications. It provides memory management, a common type system, and also language interoperability. Going into details of these topics is not in the scope of this article, therefore, we are not going to explain them.
The Rise of .NET Core
Due to the rise of different devices and cloud computing, in the past few years, software development trends have changed quite rapidly. Along with Windows, other operating systems usage has also increased.
A large number of software and services are now being developed for different platforms. Because of this trend, Microsoft started developing a new framework that can fulfill the requirements of the current as well as future software development needs.
Hence, they developed a new framework called .NET Core. It is an open-source and cross-platform implementation of .NET. It shares many of its characteristics with .NET Framework but there are differences as well which we are going to discuss in a while.
All aspects of .NET Core are open-source including class libraries, runtime, compilers, languages as well as application frameworks. .NET Core also supports C#, Visual Basic, and F#. It can run the application code with the same behavior on multiple architectures, including x64, x86, and ARM. It has a flexible deployment model in which it can be included in the application or installed side-by-side (user-wide or system-wide).
.NET Core can also be used with Docker. It also includes command-line tools that can be used during local development and most importantly in continuous integration.
Currently, all the innovations and major enhancements are being made in .NET Core. However, the .NET Framework is also being developed but at a much slower pace.
What is .NET Standard?
.NET Standard is a specification (not an implementation of .NET) that defines the set of APIs that all .NET implementations must provide. It addresses the code sharing problem for .NET developers across all platforms by bringing APIs across different environments.
We can think of it as another .NET Framework, except that we use it to develop class libraries only. .NET Standard is a successor of the portable class library.
Ok, so .NET Standard specifies the APIs that need to be implemented.
But which APIs does it cover?
To answer this question in short – there are multiple versions of the .NET Standard. Each version includes a set of APIs which we are going to cover in a while.
Confusion about .NET Standard
Newcomers to .NET who try to understand the .NET Standard can easily get confused in the beginning.
And here’s one of the reasons why that might be.
When we open up Visual Studio 2019 and go to the Create a new project window, we’ll see three types of class library projects; Class Library (.NET Standard), Class Library (.NET Framework), and Class Library (.NET Core).
If we carefully read the description which is written under Class Library (.NET Standard) and Class Library (.NET Core), it says that target platforms are .NET Standard and .NET Core respectively. This might give us a feeling that the .NET Standard is another framework or implementation of .NET:
Furthermore, let’s create three projects for each platform:
- StandarLib is a Class Library project type that targets the .NET Standard
- NetCoreWebApplication is a Web Application type project which targets the .NET Core
- WindowFormApp is a Windows Form type project which targets the .NET Framework
If we take a look at the properties of all three projects, we can see each property window has a field named Target framework; which is right for the .NET Framework and .NET Core projects.
But for the .NET Standard project, it might be misleading, because, newcomers might think of it as a framework and not a specification:
The official documentation introduces .NET Standard as a specification and tries to distinguish it from the framework but this distinction doesn’t seem to be reflected in the development tools.
.NET Framework vs .NET Core
Now we understand that .NET Framework and .NET Core are two different .NET implementations, therefore, both can be compared.
.NET Framework
- The .NET Framework is the first implementation of .NET which works on Windows only
- Its source code is public but Microsoft doesn’t accept third party contributions for it
- It has a very rich desktop top development framework for windows which include Windows Forms and WPF
- A huge third-party packages library is also available for it
- It doesn’t support the in-app deployment model
- Although it can be used with a docker container, its image size is large and can only be deployed on Windows containers
.NET Core
- .NET Core is the latest implementation of .NET which runs on Windows, Linux, and macOS
- Its open-source and Microsoft accepts third party contributions to .NET Core
- It supports desktop frameworks like Windows Forms and WPF from version 3.0
- The .NET Core also has support for a large number of third party packages as well but still, it doesn’t compete with .NET Framework in this area
- It does support in-app deployment model
- It is the best choice to work with docker containers
.NET Framework and .NET Core vs .NET Standard
Because .NET Framework and .NET Core are .NET implementations, therefore, we can compare them together against the .NET Standard.
.NET Framework and .NET Core
- The .NET Framework and .NET Core are implementations of .NET
- Both frameworks have runtime which manages the execution of applications
- The base class library is also a part of both frameworks
- We can create different types of projects in either framework
.NET Standard
- The .NET Standard is a specification and not a .NET implementation
- It specifies a set of APIs that all the .NET implementations have to implement
- We can create only class library type projects with it
Deciding Target Platform and Version
Let’s discuss what point should we keep in mind while choosing the target platform and their versions.
We should use the .NET Core:
- While developing applications for cross-platform
- For the development of microservices
- When we want to use Docker containers
- To develop high-performance and scalable systems
Use the .NET Framework when:
- We want to target only Windows
- Our application uses some third party packages which are not supported by .NET Core
- The application uses .NET technologies that are not available for .NET Core
.NET Standard should be the choice when:
- We want to share our common code across different .NET implementations
Once we choose the right platform and project type for our application, the next step is to use the correct version. Let’s suppose that we have to target both, the .NET Framework and .NET Core and we also want to share the common code across both of these platforms.
Of course, the .NET Standard class library will be our choice here. Choosing the correct version for this scenario would have been quite challenging, but fortunately, Microsoft has provided us with a nice helpful chart:
As shown in this chart, the first row mentions the different versions of .NET Standard and all other rows mention the different versions of various platforms supported by it.
For example, if we choose 1.6 version of .NET Standard for our class library project and reference that library in .NET Core and .NET Framework projects then according to this chart we must choose 1.0 version for .NET Core project and 4.6.1 version of .NET Framework project.
The same goes for all other versions.
Conclusion
We have tried to remove that confusion among the .NET Framework, .NET Core, and .NET Standard by clarifying these concepts and comparing them with each other. We have also shown how to choose the target platform and its version depending on our needs.
Great article. I understood that the best choice to create a lib or SDK is .Net Standard and the best choice to create final systems is .Net Core/Framework. Right?
Hi Diego. Yeah, that’s correct. .NET 5 and above implement .NET Standard 2.1 so if you have a code that you want to share your code between different .NET implementations, .NET Standard is the way to go.
Thank you for the article, it was incredibly helpful to a newbie like me!
You are most welcome.
Great.
Nice explanation
thanks, good article!
I created a Blazor app, which says .NET Standard 2.1, and yet it runs. So how can .NET Standard be only class libraries? It must be using a version of the framework to run.
Thanks, this clears a lot up. But one question, if I create a project type of “Class Library (.NET Standard)” which implementation am I using (since Standard is not an implementation).
Hey Lou, thanks!
Here’s a gist by David Fowler that will probably help you understand it even better.
https://gist.github.com/davidfowl/8939f305567e1755412d6dc0b8baf1b7
Go through the comments as well and try to visualize it.
Great read! Thanks for all of the clear and understandable articles!
You are very welcome. Best regards.