Commonly Used Dot Net CLI Commands

Dot net core was a revolutionary step up in many ways, from the old dot net framework. But one of the fav things I love about core is its cross platform support. And if we learn some of the CLI commands we can use it across Windows, MacOS or Linux.

dotnet new creates a .net project followed by template of choice

Some of the common templates are :

Console Application – console

Worker Service – worker

Blazor Server App – blazorserver

Blazor WebAssembly App – blazorwasm

Asp.Net Empty – web

Asp.Net Core Web App (MVC) – mvc

Asp.Net Core Web App – webapp

So if we wanna create a brand new razor page application:

dotnet new sln -n MyApp
dot net new webapp -o MyApp
dotnet sln add MyApp

sln creates the solution, webapp creates a asp.net core application and the third line adds the app to the solution

Next set of commands would be :

dotnet restore //Not relevant nowadays since Visual Studio would always do it by default, but important for CI/CD pipelines. It brings all the dependencies related to the project to the local folder. The dependencies are listed in the csporj file which inturn is a XML file

dotnet build //Builds the application and if there are no errors, will produce the output

dotnet run //Takes the above build output to run the application

Another common feature is to add Nuget packages. For that use the below command, replacing ### with the package name

dotnet add package ###

Leave a comment

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