.NET 5 – How to start

Would you like to learn how to write programs in .NET and find out what the platform from Microsoft can do? What tools to use and where to start? You’ve come to the right place! I will explain everything step by step.

What is .NET?

.NET is a programming platform created by Microsoft. Here are the most important features:

  • You can write in many languages: C #, F # and VB.NET
  • libraries written in different languages ​​in .NET can work together because they are compiled into IL intermediate code
  • .NET 5 and associated technologies are open and their sources are available on the GitHub platform
  • in .NET 5 you can build console applications, websites, APIs, games, mobile applications and desktop computers
  • .NET is extremely popular, therefore it has many ready integrations with Amazon or Google technologies, but the easiest way will be to work with Microsoft products and the Azure cloud
  • the program written in .NET 5 can be easily run on Windows, Linux and MacOS

Of course, these few points in no way exhaust the topic, because you could easily write a few books what .NET is capable of, but at the beginning it’s a quick summary is enough.

What do I need to install?

To build applications you need to install the development tools package, i.e. the SDK. To run them – the development package.

You’ll find both here: https://dotnet.microsoft.com/download/dotnet/5.0

When choosing the Runtime, choose the one that you need:

  • ASP.NET Core – for building a web application
  • Desktop – for building Windows-based desktop applications
  • .NET Runtime – for building console applications

One of the above is enough to start with. I would recommend ASP.NET Core.

What to write programs with?

Apparently, a good programmer will cope with a notepad, but I think this era is long over. There are actually two good options to choose from.

Visual Studio

A huge and very popular code editor. It is a real multi-tool, it is perfectly integrated with all Microsoft technologies, especially the older ones. I use it for many years and I can’t imagine working without it.

The most important features:

  • convenient editor, where many things can be done from UI
  • support for older Microsoft technologies
  • available on Windows and MacOS
  • paid, however, there is a free, stripped-down version – Community

Visual Studio Code

Simple, cross-platform code editor, developed open-source. It does not have as many integrations as Visual Studio, but it is lightweight and thanks to free extensions, it can be easily adapted to your needs. Certainly, however, it works comfortably with smaller projects and with websites. I use it when I’m working with React.js, for example.

The most important features:

  • is fast and light
  • it’s free and it’s easy to customize
  • works under Windows, Linux and MacOS
  • integration with older Microsoft technologies is not the best, but with .NET Core and .NET 5 it works great 

Your first app

The wizard in Visual Studio

The easiest way to create your first program in .NET 5 is to use one of the ready-made programs in Visual Studio. This environment offers us many options to choose from:

The simplest project that you can choose to start with is the console application in C #. However, if you prefer to start with a web project, select ASP.NET Core application.

 

To make sure you’re using .NET 5, edit the project file and check what value is entered in the TargetFramework should be net5.0.

 

To start the project, simply press F5. At this point, the console application will start and a black window will appear saying Hello World!.

New project in Visual Studio Code

.NET Core and .NET 5 are released together with .NET CLI, a cross-platform set of commands that allows you to create, build, and publish .NET projects. Cross-platform is an important word here – it is thanks to CLI that we can build and run programs in .NET 5 not only on Windows but also on Linux and MacOS.

Let’s create a new project. When we open Visual Studio Code, open a new terminal and enter the dotnet new --list command to see what projects are currently available.

To create a console application called ConsoleApp2, type dotnet new console -n ConsoleApp2.

Great, we already have a console application with a single C# file called Program.cs. We need to know two more commands:

  • dotnet build–  to build the app
  • dotnet run – to run the app

After a few seconds, your eyes will see a black window with the program.

The summary

Programming in .NET 5 can start very quickly and after a while writing your own programs. In addition, they will work not only on Windows but also on Linux and MacOS. They can also operate in the cloud, e.g. in containers. The possibilities are really huge.

If you would like to learn more about programming in the console, take a look at the series of my articles: How to make you console app look cool

If you’re starting your adventure with .NET, you’ve come to the right place. Subscribe to my blog and get information about new posts – you will definitely learn something interesting from them.

Cheers and good luck 🙂

6 thoughts on “.NET 5 – How to start

  1. Great article, but why so microsoft-centric?

    Many architects succesfully deploy .net solutions in AWS and GCP. Alternative editors exist, such as Sublime (with omnisharp), Jetbrains Rider, …

    There is a .Net world outside Microsoft too…

    1. Agree, there’s more than Microsoft solutions!
      It is due to my experience, cause I always worked with Visual Studio. I’m more comfortable with writing something I know. Thanks for sharing!

      1. I’d like to echo Jer0enh’s comment.

        With one of the big selling points of .NET Core being its cross-platform support, it’s unfortunate that this post focuses so much on the Windows options and doesn’t call out options for anyone using Mac/Linux by at least acknowledging cross-platform alternatives like Rider (heck, it’s amazing on Windows too!).

        Even if you’ve not used it before I still feel it’d be valuable to anyone new to the ecosystem to know it exist and stops Mac/Linux reads feel excluded.

Leave a Reply

Your email address will not be published. Required fields are marked *