Getting started with .NET Core

In the previous article, we saw what is .NET Core and what can we build with it. In this article, we will install .NET Core and start with some basic examples using the command line and Visual Studio Code.

This tutorial can be done using Windows, Linux or macOS..

Installing .NET Core

When the installation is complete, you should be able to open a command line interface (CMD, PowerShell for Windows, Terminal for Linux and macOS) and check if the installation was successful by executing the following command: dotnet.

Output for the dotnet command in PowerShell. The output is similar for Linux and macOS.

At this point, you have successfully installed .NET Core and you can start building applications.

Building a .NET Core application using the command line interface

In Windows PowerShell or the Linux / macOS Terminal, let’s create a new directory. I will call it dot-net-tutorial and navigate to it and create a new console application here using the dotnet new command.

mkdir dot-net-tutorial
cd dot-net-tutorial
dotnet new

This is how it should look like after executing these commands.

Notice how we got two files after creating the project

Program.cs– C# file containing the entry point in the console application – the Main method

In a future release, the project file will return to a .csproj extension in order to maitain compatibility with all Visual Studio and Xamarin projects.

Calling dotnet restore will restore all dependencies of the application.

dotnet restore

dotnet restore calls into NuGet to restore the tree of dependencies. NuGet analyzes the project.json file, downloads the dependencies stated in the file (or grabs them from a cache on your machine), and writes the project.lock.json file. The project.lock.json file is necessary to be able to compile and run.

The project.lock.json file is a persisted and complete set of the graph of NuGet dependencies and other information describing an app. This file is read by other tools, such as dotnet build and dotnet run, enabling them to process the source code with a correct set of NuGet dependencies and binding resolutions.

At this point, we can run the application and see if the output is the expected one using the dotnet run command.

This is how you create, build and run a basic .NET Core application using the command line.

Installing Visual Studio Code

We saw how to create, build and run applications from the command line, now it is time to move to a complete code editor that has IntelliSense and debugging built in – Visual Studio Code.