.NET CLI

Updated: 20 February 2025

sln

Add the PrimeService.Tests project to the current solution file

dotnet sln add ./PrimeService.Tests/PrimeService.Tests.csproj

add

Add a reference to lib.csproj inside app.csproj

dotnet add app/app.csproj reference lib/lib.csproj

Add or updates a package reference in a project file

dotnet add package docopt.net

new

Creates a new project, configuration file, or solution, based on the specified template. Templates which come pre-installed with the .NET SDK

Initiate a project for creating a command-line application

dotnet new console --name our_project

Initiate a project for creating a command-line application and generate an explicit Program class and Main method instead of top-level statements.

dotnet new console --name file-encrypt --use-program-main

Display a list of all installed templates

dotnet new list

Create a Class Library project

dotnet new classlib --name MyClassLib

Create a NUnit 3 Test Project

dotnet new nunit

run

Build and test the Release version of a console application

dotnet run --configuration Release

test

Run the tests in the project in the current directory

dotnet test

clean

Clean up the output of the previous build. Both intermediate (obj) and final output (bin) folders are cleaned.

dotnet clean

restore

Restores the dependencies and tools for a project i.e. external libraries in NuGet packages. All dependencies become available in a local cache and can be used by the .NET CLI to build and run the application.

dotnet restore

dotnet

List installed Software Developer Kits

dotnet --list-sdks

List installed runtimes

dotnet --list-runtimes

build

Build a project and its dependencies using Release configuration

dotnet build --configuration Release

Build the project and its dependencies into a set of binaries.
The binaries include the project’s code in Intermediate Language (IL) files with a .dll extension.

dotnet build

publish

Publishes the application and its dependencies to a folder for deployment to a hosting system.

dotnet publish

Attempt to target Linux

dotnet publish --runtime linux-x64 -p:PublishSingleFile=true --self-contained false

format

Check for violations of rules in an .editorconfig file

dotnet format --verify-no-changes

Leave a comment