.NET – CLI overview

By | 26/10/2022

In this post, we will see some commands of .NET command-line interface (CLI) that can help us to be more productive.
CLI is a cross-platform toolchain for developing, building, running and publishing .NET applications; in order to run CLI commands, we can use either Terminal (CMD) or Powershell.
For the complete list of commands, we can check out here.

Listing all templates:

dotnet new --list


Listing all templates matching a substring:

dotnet new --list Web


Creating a project:

dotnet new webapi -n test.webapi.services -f net6.0

webapi => project template
-n => project name
-f => .net framework

If we open the project with Visual Studio, we can check that everything has been created correctly:


List of all options to use with “dotnet new”:

dotnet new --help


Building of a project with all its dependencies (we have to run it in the project’s directory):

dotnet build


Running source code (we have to run it in the project’s directory):

dotnet run

If we open a browser and we go to https://localhost:7204/swagger/index.html, this will be the result:


Publishing the application and its dependencies:

dotnet publish


Cleaning the output of a project:

dotnet clean


Adding a package:

 dotnet add package "package name"


List the latest available version of the .NET sdk:

dotnet sdk check



Leave a Reply

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