The .NET application platform is Microsoft’s bet for developing desktop applications, web services, and mobile applications, being one of the most widely used development technologies at the moment.
Launched on November 8, 2021, .NET 6 is the new LTS (long time support) version, which comes to replace .NET 3 Core and to finish the work started with .NET 5, especially in terms of unification.
This is precisely one of the strong points of .NET 6, achieving convergence between .NET technologies and the unification between architectures and operating systems.
This means that .NET 6 can natively run on different architectures and operating systems. Thus, .NET 6 is natively compatible with Windows, Linux, Android, and macOS (among others), and x86, x64, ARM32, and ARM64 processors.
Other improvements include performance enhancements, compatibility with C# 10, improvements for simplifying development, and improvements for productivity in development. In addition to MAUI, which will allow us to create graphical applications with a unified UI.
The next LTS version of .NET will be version 8, whose date is not expected until November 2023. So, for a while, .NET 6 will be the “preferred” version for Microsoft technology development.
In this post, we will introduce the use of .NET 6 with a simple example, a “Hello World” application, executed under Windows system.
In future posts, we will delve into the topic, especially in the use of Linux and Raspberry Pi, which is one of the most interesting aspects of .NET 6.
Installing .NET 6 SDK
Logically, we will need to have .NET 6 installed. This comes hand in hand with the “dotnet” executable, a CLI application that allows us to create and manage projects.
In the case of Windows, by installing Visual Studio Community, we will have everything installed, so it generally will not be necessary to install anything else.
However, we can always install .NET by downloading the appropriate version from the official website. https://dotnet.microsoft.com/en-us/download/dotnet
Check that we have dotnet installed
First of all, it is advisable to make sure that you have everything installed correctly. This is as simple as doing,
dotnet --version
If we have everything correctly installed
Create a new application with Dotnet
To create a console application we use the command
dotnet new <template>
Whereis the type of project we want to create. For example, this is how we would create a console application called “helloWorld” Examples of templates are console, classlib, wpf, xunit, web, webapp, webapi. You have a list of the standard templates at this link https://docs.microsoft.com/es-es/dotnet/core/tools/dotnet-new. To check the templates we have installed, we can do, To install an additional template, we would simply do, Once our project is created, we can edit it with our favorite IDE. Normally in Windows, we will work with Visual Studio, which as we know has a Community version that you can use freely in non-commercial projects. In other platforms such as Linux, and even in Windows itself, Visual Studio Code is also very popular as a lightweight development environment. In any case, any text editor will do. So, use the one you like the most. When opening the ‘Program.cs’ file, we will see the content of our “Hello world”. This simple example simply has one line that prints “Hello, World!” To run the application, we simply have to access the directory of our project, and run the ‘run’ command We will see that, indeed, the message is displayed on the command line. When using ‘run’, the .NET environment installed on the machine will be used. Therefore, it will not work if we move it to another machine that does not have .NET installed. To create a standalone executable, which does not require .NET to be installed on the machine where we are going to run it, we must publish it with the ‘publish’ command. Where For example, we can do In the following posts, we will delve into the use of .NET 6, and we will see how to install it on different machines, with different operating systems. Especially, in Linux and Android. And, knowing us, we know that we are going to end up installing it on a mini-PC like Raspberry Pi. But that will be in future posts. Until next time!dotnet new console -o helloWorld
dotnet new --list
dotnet new install <template>
Edit NET6 application
Console.WriteLine("Hello, World!");
Run application
cd
helloWorld
dotnet run
Create a standalone executable
dotnet publish -c <configuration> -r <runtime>
dotnet publish -c release -r linux-x64