100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
.NET

.NET CLI Basics

How to use the dotnet command-line interface to scaffold, build, test, and publish .NET applications.

FoundationsBeginner8 min readJul 10, 2026
Analogies

.NET CLI Basics

The dotnet command-line interface (CLI) is the primary tool for creating, building, running, testing, and publishing .NET applications, and it ships with every SDK installation. It works identically on Windows, Linux, and macOS terminals, which means the exact same commands — dotnet new, dotnet build, dotnet run — work regardless of which OS a developer or CI pipeline uses.

🏏

Cricket analogy: Like the standard set of umpire signals (four, six, out) understood identically at every cricket ground worldwide, the dotnet CLI commands behave identically whether you're on a Windows laptop or a Linux CI server.

Creating and Running Projects

dotnet new scaffolds a new project from a template — dotnet new console, dotnet new webapi, and dotnet new classlib are among the most common. Running dotnet new list shows every installed template, and dotnet new install <package> adds third-party templates such as those published by Ocelot or MediatR maintainers. Once a project exists, dotnet run compiles and executes it in one step, automatically restoring NuGet packages first if needed.

🏏

Cricket analogy: Like choosing a pre-set fielding template (e.g., a 'death overs' field) before adjusting it for the specific batter, dotnet new webapi scaffolds a ready-made starting structure you then customize.

Building, Testing, and Publishing

dotnet build compiles the project and its dependencies into intermediate output under bin/Debug/<TFM>/ without running it, while dotnet test discovers and executes test projects using frameworks like xUnit, NUnit, or MSTest and reports pass/fail results. dotnet publish produces a deployable output — by default framework-dependent, or self-contained with --self-contained true -r linux-x64 — ready to copy to a server or bake into a Docker image.

🏏

Cricket analogy: Like a net practice session (dotnet build compiling without a real match) versus an actual televised match (dotnet run), and finally packing the team kit bag for an overseas tour (dotnet publish), these three commands represent progressive stages of readiness.

bash
# Scaffold, build, test, and publish a Web API project
dotnet new webapi -n OrdersApi
cd OrdersApi

dotnet build

dotnet new xunit -n OrdersApi.Tests -o ../OrdersApi.Tests
cd ../OrdersApi.Tests && dotnet add reference ../OrdersApi/OrdersApi.csproj
dotnet test

cd ../OrdersApi
dotnet publish -c Release -r linux-x64 --self-contained true -o ./publish

dotnet run always rebuilds if source files changed, but it does NOT automatically restore new NuGet packages added directly to the .csproj by hand in some SDK versions — run dotnet restore explicitly if you edit package references outside of dotnet add package.

  • The dotnet CLI ships with the SDK and provides identical commands across Windows, Linux, and macOS.
  • dotnet new <template> scaffolds projects; dotnet new list shows installed templates.
  • dotnet build compiles without running; dotnet run compiles and executes in one step.
  • dotnet test discovers and runs test projects built with xUnit, NUnit, or MSTest.
  • dotnet publish produces deployable output, optionally self-contained with a runtime identifier like linux-x64.
  • dotnet add package and dotnet add reference manage NuGet packages and project references from the terminal.
  • dotnet restore explicitly re-resolves NuGet dependencies when needed.

Practice what you learned

Was this page helpful?

Topics covered

#NET#NETCoreStudyNotes#MicrosoftTechnologies#NETCLIBasics#CLI#Creating#Running#Projects#StudyNotes#SkillVeris