.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:

1
dotnet new --list


Listing all templates matching a substring:

1
dotnet new --list Web


Creating a project:

1
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”:

1
dotnet new --help


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

1
dotnet build


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

1
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:

1
dotnet publish


Cleaning the output of a project:

1
dotnet clean


Adding a package:

1
dotnet add package "package name"


List the latest available version of the .NET sdk:

1
dotnet sdk check



Leave a Reply

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