INSTALL NET 5.0

Before talking about “Development environments” it is necessary to install the NET 5.0 SDK. With your browser go to the address: https://dotnet.microsoft.com/download/dotnet/5.0 and download the SDK for your Operating System. Once you have downloaded and installed NET 5.0 open a command prompt and type: dotnet –version. The version of the SDK you just installed should appear.

dotnet version

DEVELOPMENT ENVIRONMENTS

  • Visual Studio, is ideal for those who already have experience with the .NET Framework. It is a complete development environment that also includes profiling tools to measure the application’s CPU and RAM consumption. Its limitation is that it only works on Windows;
  • Visual Studio for Mac is for those who use macOS and want to build both ASP.NET Core applications and native mobile applications with Xamarin. Although it bears the name “Visual Studio”, it is not as comprehensive as its Windows counterpart;
  • Visual Studio Code is an editor available for all platforms. It is very light and suitable for projects made with various languages and technologies. To create ASP.NET Core applications we need to install the C # extension which adds language support and provides various aids to typing code. It is ideal for first-time users or developers who want to have flexibility and work on different projects.

DEVELOPMENT ENVIRONMENTS – LINK TO DOWNLOAD

Download link to the community version, the free version of Visual Studio.

https://visualstudio.microsoft.com/it/

The link is the same for both Visual Studio for Mac and Visual Studio Code the cross-platform editor we will use to learn C#.

DEVELOPMENT ENVIRONMENTS – THE COMMAND LINE AND THE DOTNET COMMAND

To help us get started, the dotnet command comes with built-in help that you can call up at any time by adding — help at the end of the command. The guide is context sensitive, here are some examples:

  • dotnet –help displays all available commands;
  • For example, to see all available templates use the dotnet new –list command.
  • To see the current SDK version type: dotnet –version, to see the list of all installed SDKs type: dotnet –list-sdks etc.

SOME USEFUL SUBCOMMANDS TO KNOW

The dotnet command allows us to access many features, each accessible by a specific subcommand. Let’s see some of the most useful

  • new to create new applications from a template;
  • add to add references to NuGet packages or other projects;
  • build to build the project;
  • run to run the application (which will implicitly also compile if necessary);
  • dev-certs to manage SSL certificates.

DEVELOPMENT ENVIRONMENTS – VISUAL STUDIO CODE

If you have not already done so, download Visual Studio Code from the following address:

https://visualstudio.microsoft.com/it/.

Download the version suitable for your Operating System, I will use Windows 10. Once downloaded and finished the installation, open the editor. We will be faced with the following screen:

Visual studio code

VISUAL STUDIO CODE

Visual Studio Code is a lean editor and suitable for anyone because it is easy to use and can be installed on any platform. At the start of the program we find a welcome page that summarizes: the various useful resources to learn how to use it; a list of the last open projects. To open a new project, we click the menu File> Open Folder …, or we press the keys Ctrl + K and immediately afterwards Ctrl + O (this is what is called an “agreement”). When opening any C# file, if we have already installed the C# extension, we will be offered to create the necessary configuration to start and debug the application with Visual Studio Code. By accepting, a .vscode subdirectory will be created that contains all the build configuration and start current project. The application can then be started in debug with the F5 key.

THE VISUAL STUDIO CODE UI

The Visual Studio Code graphic interface consists, on the left side, of a vertical bar with 5 buttons for accessing the following panels:

  • Explorer: lists all the file hierarchy contained in the directory we have opened;
  • Search: allows you to search for a text string in all files, possibly using regular expressions;
  • Source Control: allows you to see which files have been modified since the last commit and to perform other operations related to the control system
    version we are using, such as GIT;
  • Debug: it contains several panes which are helpful when debugging the application;
  • Remote Explorer;
  • Extensions: This is where you install extensions that add functionality and support to other languages in Visual Studio Code.
    Some extensions may add new buttons to the vertical bar, and this is a demonstration of what the entire Visual Studio Code interface is
    easily extendable and customizable according to various needs.

QUICKLY CALL UP ANY EDITOR FUNCTIONALITY

Visual Studio Code has a Command Palette, which consists of a multipurpose text box that can be called up with various keyboard shortcuts. Depending on the shortcut used, the Command Palette offers different functionalities:

  • With F1 it prepares to search and execute one of the commands available in Visual Studio Code. Some of these commands can also be recalled from the menus (for example: setting the theme to change the colors and the style of the interface);
  • With Ctrl + P allows you to search and open files by name;
  • With Ctrl + T you activate the search by symbol throughout the application. A symbol is an element in the source code that has a name, such as ad
    example a class, a method, a property, a private field, a constant, an enumeration, an interface and so on;
  • With Ctrl + Shift + O you search among the local symbols, that is defined in the currently open C # code file;
  • With Ctrl + G you can jump to the indicated line of the currently open file. Navigating the Code To be more productive and less tired at the end of the day, it is important to know a few keyboard shortcuts to navigate the code more easily.
  • With F12 we jump to the file in which the symbol on which the cursor is located is defined;
  • With Alt + F12 you can see the definition of the symbol inside a popup window (called “peek” window);
  • With Shift + F12 all references to the symbol on which the cursor is located are displayed, that is, all the points where that symbol is used;
  • With Alt + → or Alt + ← we move the cursor forward or backward along all the positions in which it was found. So it’s a great way to move between two or
    multiple files we are working on.

DEBUG THE APPLICATION

Thanks to the use of a debugger provided with the C # extension, we can plug into the dotnet process and stop its execution at a specific point. This gives us plenty of time to inspect the value that the variables have taken in that context and determine if it is what we expected.

  • With F5 we start the application in debug;
  • With F9 we add or remove a breakpoint at the line we are in. Breakpoints can be
    also set by clicking the white space to the left of the page number; When execution stops, press F5 to resume it, or F10 to advance step by step.
  • With F11 we enter the definition of a method;
  • With Shift + F5 we restart the application after making a change to the source code. In fact, it is necessary to restart the application, at least when using Visual Studio Code. In the Debug panel we find various panels useful for inspecting the state of the application when it is stopped at a breakpoint;
  • Variables lists all the in-scope variables, that is, accessible in the context of the line of code on which execution stopped;
  • Watch allows us to add arbitrary expressions that will be evaluated on the fly;
  • Call-stack shows the call hierarchy (which method called the method that called our method);
  • Breakpoints lists all breakpoints set in the application.
    Learning how to use the debugger well is the key to finding and fixing bugs as quickly as possible.