In this post we are going to look at the different versions of .NET. Especially when you're starting out with the platform, a lot of questions arise, because whether due to marketing or trial and error, Microsoft has not always been very precise in the past when it comes to naming.
Although as we will see, this problem won't be so significant in the future.
Index
1 - The .NET Environment
On this channel, we mainly write code in C#, and for that reason, I have other posts where this code is explained. But at the end of the day, we write text in a document, so we need software that can understand that document and run it on the machine.
In the case of C#, the software that transforms the code into a language the machine can understand is a framework called .NET.
C# is a part of .NET, but it’s true that in 99% of cases, you’ll refer to C#, although it’s not the only language.
The .NET Framework is capable of converting not only C#
, but also F#
and Visual Basic
into code that the machine can understand.
2 - What is .NET Framework?
In 2002, Microsoft decided to release .NET Framework
, almost 20 years ago, and to be honest, it is still widely used today.
.NET Framework
is the engine that understands your code in C#, F#, or Visual Basic and executes it against the machine through the Runtime
. It’s also responsible for compiling the code or the garbage collector.
Besides providing the CLR
(Common Language Runtime), when we program in .NET Framework
we use the code library provided by Microsoft, which contains a wide variety of features, classes, interfaces, types, and many other characteristics.
Finally, with it, we can create web applications with ASP.NET, desktop applications with Windows Presentation Foundation, or, if they are older, winforms and console applications.
- Note: It’s also important to mention that .NET Framework provides us access to Windows APIs or other Microsoft software, such as Excel or Word. We have all worked at the typical company that has the Office suite installed on the server to do some invoicing and similar tasks with the software.
As a downside, applications written with .NET Framework only run on Windows and in the case of web applications, they have to be hosted on IIS (Internet Information Server).
Finally, applications written with .NET Framework are very heavy (in megabytes).
2.1 - When to Use .NET Framework?
If you are reading this post, it’s at least 2021, so I’ll be clear: NEVER.
We’ll look at the other options below.
3 - What is .NET Core?
Much like the previous one but more modern, this engine was launched with its version 1 in 2016 and is completely open source, which has been crucial, as the community welcomed it with open arms and that has greatly helped its development over the years.
The way applications run on .NET Core is a bit different from how they ran on .NET Framework. With .NET Core we run everything on our appHost
, which has access to the .NET Core
library and the Core CLR
.
It's important to emphasize that it runs the core versions of the library and CLR because they are not the same as in .NET Framework; they have been refactored and in many cases split into multiple libraries to make them lighter.
This allows your application to be very lightweight since you have only the extremely necessary libraries or packages for it to run. Of course, you can add whichever ones you want, either from the community via nuget or your own.
Because of this modularization, today .NET comes with packages to create default web projects, whether MVC, API, or Blazor, either server-side or with WebAssembly.
And Universal Windows Platform apps for building desktop applications.
An important point in switching to .NET Core is that code can be run on multiple platforms and architectures (x86, x64, ARM CPUs). If you create a web application, you can run and develop it on Windows, Linux, or Mac.
This is a big advantage for companies in economic terms. And an important advantage for users like me who have a small blog, since the cost of a Linux server is half that of a Windows server.
Another benefit is that you can install as many runtimes as you want on your machine, to make all your applications compatible. Although it is possible to do so, it’s not absolutely necessary since .NET Core is always backward compatible. So, if you have the latest version of .NET Core installed, all your apps written in .NET Core will run correctly.
Finally, when you build applications with .NET Core, you can specify that it’s a “self-contained application” that will not only be your application but will also contain all the necessary components for it to run on any machine, including the runtime
3.1 - When to Use .NET Core?
Today, at the end of 2021, we should use .NET Core version 3.1 for those web, console, or desktop products that you want in production and want to be stable.
You have to keep in mind that .NET Core 3.1 is an LTS version, which means it has long-term support. Specifically, .NET Core 3 was released in December 2019 and support ends in December 2022, providing three years of support from Microsoft (security patches, updates, etc.).
4 - What is .NET?
The title of this section might seem a little redundant because it makes you think we’re referring to the entire .NET environment. In a way, yes, but here we're talking about the framework itself.
As you may have guessed, the .NET community had doubts about the name .NET Framework versus .NET Core.
But, what did Microsoft think about it?
Well, Microsoft decided the best thing was to combine both frameworks. So they needed a new name, and in this case, they chose .NET
(plain), which seems to have confused things further. Still, in a few years, no one will remember this moment.
So yes, Microsoft combined .NET Core with .NET Framework and called it .NET; specifically, the first version was .NET 5.
And in theory, it’s completely backward compatible with both frameworks, but I haven’t tested from .NET Framework 4.8 to .NET 5; from .NET Core 3.1 it works fine. In fact, this website was initially developed in .NET Core 3.1 and then migrated to 5.
4.1 - When to Use .NET?
In a few months, we’ll be able to enjoy .NET Conf 2022, where they will officially announce .NET 6. Right now, it’s available in preview, but currently, the version we should choose is .NET 5.
That said, we’ll have to migrate to .NET 6 in May 2022, which is when .NET 5 reaches end of support, since .NET 6 will be LTS.
There’s not much more to say, there’s no reason not to create your projects in .NET 5 or 6 in case you don’t mind putting them into production before the new features are fully stable.
5 - What is Xamarin?
Finally, within .NET, we have another runtime, called “mono
”. Originally, mono
was a fork of the .NET runtime with the aim to run .NET applications on multiple platforms.
In fact, many years ago (I’m getting old now) it was possible to code in C# on Mac via XCode using mono.
Today it is used for creating mobile applications (Android, OSX) or apps for Mac.
5.1 - When to Use Xamarin?
Currently, if you want to create mobile applications, I would recommend Xamarin.
With .NET 6, Blazor bindings and .NET MAUI
(Multi-platform App) were supposed to be released. But it seems they had to delay them.
In this post Scott Hunter explains the reason, and basically it did not meet some quality standards and they prefer to release it later, more or less mid-2022.
6 - What is .NET Standard?
Finally, let's see what .NET Standard
is, which I’m sure you’ve heard about.
To summarize, .NET Standard is intended for code that will be shared between different runtimes, since all runtimes (.NET Framework, .NET Core, Xamarin) are capable of running code written in .NET Standard.
But .NET Standard
by itself cannot be executed. That is, you cannot create a console application that is .NET Standard. It would need to be .NET Core, and then maybe you use some common code that is NET Standard.
We can think of .NET Standard as a layer before the runtime, simply something to add to the libraries provided by the language.
6.1 - When to Use .NET Standard
If your code is .NET 5 or higher, you don’t need net standard (although it can be run) as the aim of .NET 5 is to also replace .NET Standard.
In this post, Immo Landwerth provides more info about it.
On the other hand, if you’re in the typical company that’s migrating from .NET Framework, you’re probably migrating from .NET Framework 4.8 to .NET Core 3.1 (the most common case). In this scenario, it can help you have shared code between both projects.
For example, my Railway Oriented Programming library is written in .NET Standard
Which .NET Version to Choose?
If you’re reading this post, you probably have doubts about which version to choose for your software.
As of today (September 2021): .NET 6. Now, .NET 6 is in preview until May 2022, so if you don’t want to risk some new features not working properly, you can always use .NET 5.
- Note: When
C# 10
is officially announced I will write a post covering the changes.
If you have to build a library that will be used by .NET Core, .NET, or even .NET Framework, you can use .NET Standard, and depending on the version you want to support, you'll have to choose one or another version.
For example, .NET Standard 2.0 is compatible with .NET 5, .NET Core 2.0 or higher, or even .NET Framework 4.6.1.
Finally, if what you are looking for is mobile or desktop applications, you will either have to choose Xamarin or wait until .NET 7 is released, since unfortunately, despite being on the .NET 6 roadmap, it appears to have been delayed.
If there is any problem you can add a comment bellow or contact me in the website's contact form