Creating a new .NET Core application using the dotnet command line

.NET Core is a general purpose development platform maintained by Microsoft and the .NET community on GitHub. It is cross-platform, supporting Windows, macOS, and Linux, and can be used in device, cloud, and embedded/IoT scenarios.

This is a simple guide to get you started with .NET Core by creating a simple Web API template using the command prompt. The example below, while simple, it shows how powerful and fluid this platform is.

First, let’s find out if you have the .NET Core platform installed, to do this, just open a command prompt and type the following command:

c:where dotnet

If you have it installed, the above command will show the path to the .NET Core executable. If it doesn’t show you a path to the executable, then you don’t have it yet and you can install it from here.

Now let’s find out what version is installed, in the command prompt, type the following:

C:dotnet --version

The above command will display the installed version. If you have an older version, you can get an updated version here.

One you have this platform installed, you’ll be set to create your first .NET Core application. To create a new ASP.NET Core web api, type the following commands:

// Create new directory
C:>mkdir api

// Go to that directory
C:cd api

// Create new application using the webapi template
C:api>dotnet new webapi api

// Restores the dependencies and tools of a project
C:api>dotnet restore

//Runs source code without any explicit compile or launch commands
C:api>dotnet run

Once you do this, you’ll have a running web api application. This is what you’ll see in the command prompt:

To edit this application, I recommend you download Visual Studio Code or use any other text editor.

Also, in the example above I used the templace webapi to create a ASP.NET Core web api, but there are many other templates you can use to create different applications:

Template description Template name Languages
Console application console [C#], F#
Class library classlib [C#], F#
Unit test project mstest [C#], F#
xUnit test project xunit [C#], F#
ASP.NET Core empty web [C#]
ASP.NET Core web app mvc [C#], F#
ASP.NET Core web api webapi [C#]
Nuget config nugetconfig
Web config webconfig
Solution file sln

Want to create a new Angular or React application? You can install all the available single page application (SPA) templates using the following command:

dotnet new --install Microsoft.AspNetCore.SpaTemplates::*
Templates                              Short Name        Language       
--------------------------------------------------------------------
Console Application console [C#], F#
Class library classlib [C#], F#
Unit Test Project mstest [C#], F#
xUnit Test Project xunit [C#], F#
Empty ASP.NET Core Web Application web [C#]
MVC ASP.NET Core Web Application mvc [C#], F#
MVC ASP.NET Core with Angular angular [C#]
MVC ASP.NET Core with Aurelia aurelia [C#]
MVC ASP.NET Core with Knockout.js knockout [C#]
MVC ASP.NET Core with React.js react [C#]
MVC ASP.NET Core with React.js and Redux reactredux [C#]
Web API ASP.NET Core Web Application webapi [C#]
Solution File sln

Happy coding!