Show Menu
Cheatography

dotnet cli Cheat Sheet by

dotnet commands for .NET Core 2.1

dotnet new

dotnet new sln
Solution file
dotnet new console
Console applic­ation
dotnet new classlib
Class library
dotnet new mvc
ASP.NET Core Web App (Model­-Vi­ew-­Con­tro­ller)
dotnet new xunit
xUnit test project
dotnet new -l
Obtain a list of the available templates

dotnet sln

dotnet sln list
List all projects in a solution file
dotnet sln todo.sln add todo-a­pp/­tod­o-a­pp.c­sproj
Add a C# project to a solution
dotnet sln todo.sln remove todo-a­pp/­tod­o-a­pp.c­sproj
Remove a C# project from a solution
dotnet sln todo.sln add **/*.cs­proj
Add multiple C# projects to a solution using a globbing pattern

dotnet add

dotnet add package Newton­sof­t.Json
Add Newto­nso­ft.J­son NuGet package to a project
dotnet add reference lib1/l­ib1.csproj lib2/l­ib2.cs­proj
Add multiple project references to the project in the current directory
dotnet add app/ap­p.c­sproj reference **/*.cs­proj
Add multiple project references using a globbing pattern on Linux/Unix

dotnet build

dotnet build
Build a project and all of its depend­encies
dotnet build --conf­igu­ration Release
Build a project and its depend­encies using Release config­uration
dotnet build --runtime ubuntu.16.04­-x64
Build a project and its depend­encies for a specific runtime (in this example, Ubuntu 16.04)
Starting with .NET Core 2.0, you don't have to run dotnet restore because it's run implic­itly.

dotnet run

dotnet run
Run the project in the current directory
dotnet run --project ./proj­ect­s/p­roj­1/p­roj­1.c­sproj
Run the specified project
dotnet myapp.dll
Run a framew­ork­-de­pendent app named myapp.dll
 

dotnet clean

dotnet clean
Clean the output of a project
dotnet clean --conf­igu­ration Release
Clean a project built using the Release config­uration
Only the outputs created during the build are cleaned. Both interm­ediate (obj) and final output (bin) folders are cleaned.

dotnet publish

dotnet publish
Publish the project in the current directory
dotnet publish ~/proj­ect­s/a­pp1­/ap­p1.c­sproj
Publish the applic­ation using the specified project file
The dotnet publish command's output is ready for deployment to a hosting system (for example, a server, PC, Mac, laptop) for execution.

dotnet ef

dotnet ef migrations add
Add a new migration
dotnet ef migrations list
List available migrations
dotnet ef migrations remove
Remove the last migration
dotnet ef migrations script
Generate a SQL script from migrations
dotnet ef database update
Update the database to a specified migration
dotnet ef database drop
Drop the database
dotnet ef dbcontext list
List available DbContext types
dotnet ef dbcontext info
Get inform­ation about a DbContext type
dotnet ef dbcontext scaffold
Scaffolds a DbContext and entity types for a database

dotnet pack

dotnet pack
Build the project and create NuGet packages
dotnet pack --no-build --output nupkgs
Pack the project in the current directory into the nupkgs folder and skip the build step
dotnet pack /p:Pac­kag­eVe­rsi­on=­2.1.0
Set the package version to 2.1.0 with the Packa­geV­ersion MSBuild property
 

dotnet nuget

dotnet nuget locals –l all
Display the paths of all the local cache direct­ories
dotnet nuget push foo.nupkg -k 4003d7­86-­cc3­7-4­004­-bf­df-­c4f­3e8­ef9b3a
Push foo.n­upkg to the default push source, specifying an API key
dotnet nuget delete Micros­oft.As­pNe­tCo­re.Mvc 1.0 --non-­int­era­ctive
Delete version 1.0 of package Micro­sof­t.A­spN­etC­ore.Mvc, not prompting user for creden­tials or other input

dotnet remove

dotnet remove package Newton­sof­t.Json
Remove Newto­nso­ft.J­son NuGet package from a project in the current directory
dotnet remove reference lib/li­b.c­sproj
Remove a project reference from the current project
dotnet remove app/ap­p.c­sproj reference **/*.cs­proj
Remove multiple project references using a glob pattern on Unix/Linux

etc.

dotnet help
Show more detailed docume­ntation online for the command
dotnet migrate
Migrate a Preview 2 .NET Core project to a .NET Core SDK 1.0 project
dotnet msbuild
Provides access to a fully functional MSBuild
dotnet test
Run the tests in the project in the current directory
dotnet list reference
List the project references for the project in the current directory

Enviro­nment variables

DOTNET­_PA­CKAGES
The primary package cache.
DOTNET­_SE­RVICING
Specifies the location of the servicing index to use by the shared host when loading the runtime.
DOTNET­_CL­I_T­ELE­MET­RY_­OPTOUT
Specifies whether data about the .NET Core tools usage is collected and sent to Microsoft.
DOTNET­_MU­LTI­LEV­EL_­LOOKUP
Specifies whether .NET Core runtime, shared framework, or SDK are resolved from the global location.
DOTNET­_RO­LL_­FOR­WAR­D_O­N_N­O_C­AND­IDA­TE_FX
Disables minor version roll forward. For more inform­ation, see Roll forward.
       

Help Us Go Positive!

We offset our carbon usage with Ecologi. Click the link below to help us!

We offset our carbon footprint via Ecologi
 

Comments

Keep trying to download this DOtNet CLI cheat sheet and it keeps cycling back to login/register even though I'm clearly registered. NOT IMPRESSED

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          C# Naming Conventions Cheat Sheet