Lesson Weekend

In this lesson, we'll learn more about the .NET 5.0 CLI and build an API project with the dotnet new command.


A CLI is a command line interface, which means we can use it to execute commands in the terminal. We've already been doing this with commands like dotnet build and dotnet run. However, we can also use the .NET Core CLI to quickly scaffold code for our projects with the dotnet new command.

We can see what dotnet new can offer with the following command: dotnet new --list.

Templates                                         Short Name         Language          Tags
Console Application                               console            [C#], F#, VB      Common/Console
Class library                                     classlib           [C#], F#, VB      Common/Library
Unit Test Project                                 mstest             [C#], F#, VB      Test/MSTest
NUnit 3 Test Project                              nunit              [C#], F#, VB      Test/NUnit
NUnit 3 Test Item                                 nunit-test         [C#], F#, VB      Test/NUnit
xUnit Test Project                                xunit              [C#], F#, VB      Test/xUnit
Razor Page                                        page               [C#]              Web/ASP.NET
MVC ViewImports                                   viewimports        [C#]              Web/ASP.NET
MVC ViewStart                                     viewstart          [C#]              Web/ASP.NET
ASP.NET Core Empty                                web                [C#], F#          Web/Empty
ASP.NET Core Web App (Model-View-Controller)      mvc                [C#], F#          Web/MVC
ASP.NET Core Web App                              webapp             [C#]              Web/MVC/Razor Pages
ASP.NET Core with Angular                         angular            [C#]              Web/MVC/SPA
ASP.NET Core with React.js                        react              [C#]              Web/MVC/SPA
ASP.NET Core with React.js and Redux              reactredux         [C#]              Web/MVC/SPA
Razor Class Library                               razorclasslib      [C#]              Web/Razor/Library/Razor Class Library
ASP.NET Core Web API                              webapi             [C#], F#          Web/WebAPI
global.json file                                  globaljson                           Config
NuGet Config                                      nugetconfig                          Config
Web Config                                        webconfig                            Config
Solution File                                     sln                                  Solution

    dotnet new mvc --auth Individual
    dotnet new console
    dotnet new --help

All of these templates can be used to build fully scaffolded applications. For instance, we could run dotnet new console to create a console application for us. There are also options to build an MVC application with dotnet new mvc as well as projects with JavaScript frameworks and APIs. If you choose to use this command, make sure to include the version like this: dotnet new mvc --framework net5.0. These commands are great in that they handle a lot of the boilerplate code and necessary packages while still allowing for configuration.

In the next lesson, we'll use the dotnet new command to create an API project. Then we'll modify that project to host an API of our own.

Lesson 2 of 22
Last updated April 6, 2022