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
![](https://www.zoneofdevelopment.com/wp-content/uploads/2022/10/1-1024x965.png)
Listing all templates matching a substring:
dotnet new --list Web
![](https://www.zoneofdevelopment.com/wp-content/uploads/2022/10/2-1-1024x311.png)
Creating a project:
dotnet new webapi -n test.webapi.services -f net6.0
webapi => project template
-n => project name
-f => .net framework
![](https://www.zoneofdevelopment.com/wp-content/uploads/2022/10/3-1024x969.png)
If we open the project with Visual Studio, we can check that everything has been created correctly:
![](https://www.zoneofdevelopment.com/wp-content/uploads/2022/10/4-1024x566.png)
![](https://www.zoneofdevelopment.com/wp-content/uploads/2022/10/5-1024x508.png)
List of all options to use with “dotnet new”:
dotnet new --help
![](https://www.zoneofdevelopment.com/wp-content/uploads/2022/10/6-1024x515.png)
Building of a project with all its dependencies (we have to run it in the project’s directory):
dotnet build
![](https://www.zoneofdevelopment.com/wp-content/uploads/2022/10/7-1024x846.png)
Running source code (we have to run it in the project’s directory):
dotnet run
![](https://www.zoneofdevelopment.com/wp-content/uploads/2022/10/8-1024x807.png)
If we open a browser and we go to https://localhost:7204/swagger/index.html, this will be the result:
![](https://www.zoneofdevelopment.com/wp-content/uploads/2022/10/9-1024x478.png)
![](https://www.zoneofdevelopment.com/wp-content/uploads/2022/10/10-1024x918.png)
Publishing the application and its dependencies:
dotnet publish
![](https://www.zoneofdevelopment.com/wp-content/uploads/2022/10/11-1024x951.png)
![](https://www.zoneofdevelopment.com/wp-content/uploads/2022/10/12-1024x743.png)
![](https://www.zoneofdevelopment.com/wp-content/uploads/2022/10/13-1024x588.png)
Cleaning the output of a project:
dotnet clean
![](https://www.zoneofdevelopment.com/wp-content/uploads/2022/10/14-1024x902.png)
Adding a package:
dotnet add package "package name"
![](https://www.zoneofdevelopment.com/wp-content/uploads/2022/10/15-1014x1024.png)
List the latest available version of the .NET sdk:
dotnet sdk check
![](https://www.zoneofdevelopment.com/wp-content/uploads/2022/10/16-1019x1024.png)