dotnet CLI — Complete Command Reference
The dotnet CLI is the command-line tool for building .NET applications. You must be fluent with it — used daily in development, CI/CD, and deployment.
Install & Verify
# Verify installation
dotnet --version # 8.0.xxx
dotnet --info # full SDK details, runtime versions
# List all installed SDKs
dotnet --list-sdks
# List all installed runtimes
dotnet --list-runtimes
dotnet new — Create Projects
# Create console app
dotnet new console -n SchoolManagement
dotnet new console -n SchoolManagement --framework net8.0
# Create ASP.NET Core Web API
dotnet new webapi -n SchoolManagementApi
dotnet new webapi -n SchoolManagementApi --use-controllers
# Create ASP.NET Core MVC
dotnet new mvc -n SchoolManagementMvc
# Create class library
dotnet new classlib -n SchoolManagement.Core
# Create xUnit test project
dotnet new xunit -n SchoolManagement.Tests
# Create solution file
dotnet new sln -n SchoolManagement
# Create Worker Service
dotnet new worker -n AttendanceProcessor
# Create Minimal API
dotnet new webapi -n SchoolApi --use-minimal-apis
# List all available templates
dotnet new list
dotnet run — Run Project
# Run from project folder
cd SchoolManagementApi
dotnet run
# Run specific project
dotnet run --project ./src/SchoolManagementApi
# Run with specific profile (launchSettings.json)
dotnet run --launch-profile "Development"
# Run with watch (auto-restart on file save)
dotnet watch run
dotnet watch run --project ./src/SchoolManagementApi
# Pass arguments to your app
dotnet run -- --seed-data --env=dev
dotnet build — Compile
# Build (debug by default)
dotnet build
# Build release
dotnet build --configuration Release
# Build specific project
dotnet build ./src/SchoolManagementApi/SchoolManagementApi.csproj
# Build and show detailed output
dotnet build --verbosity detailed
dotnet publish — Prepare for Deployment
# Publish for deployment
dotnet publish --configuration Release --output ./publish
# Self-contained — includes .NET runtime (no .NET needed on server)
dotnet publish -r win-x64 --self-contained true -o ./publish/win
# Framework-dependent (smaller size, needs .NET on server)
dotnet publish -r linux-x64 --self-contained false -o ./publish/linux
# Native AOT (fastest startup, smallest size, .NET 8+)
dotnet publish -r win-x64 /p:PublishAot=true
dotnet add — Manage Packages
# Add NuGet package
dotnet add package Microsoft.EntityFrameworkCore
dotnet add package Microsoft.EntityFrameworkCore --version 8.0.0
# Add project reference
dotnet add reference ../SchoolManagement.Core/SchoolManagement.Core.csproj
# Remove package
dotnet remove package Microsoft.EntityFrameworkCore
# Common packages for School Management API
dotnet add package Microsoft.EntityFrameworkCore.SqlServer
dotnet add package Microsoft.EntityFrameworkCore.Tools
dotnet add package Microsoft.AspNetCore.Authentication.JwtBearer
dotnet add package Swashbuckle.AspNetCore
dotnet add package AutoMapper
dotnet add package Dapper
dotnet add package Serilog.AspNetCore
dotnet restore — Restore Packages
# Restore NuGet packages (run after git clone)
dotnet restore
# Restore specific project
dotnet restore ./src/SchoolManagementApi/SchoolManagementApi.csproj
dotnet test — Run Tests
# Run all tests
dotnet test
# Run with verbose output
dotnet test --verbosity normal
# Run specific test
dotnet test --filter "FullyQualifiedName~StudentService"
# Run tests with coverage
dotnet test --collect:"XPlat Code Coverage"
dotnet solution — Manage Solution
# Add project to solution
dotnet sln SchoolManagement.sln add ./src/SchoolManagementApi/SchoolManagementApi.csproj
dotnet sln SchoolManagement.sln add ./src/SchoolManagement.Core/SchoolManagement.Core.csproj
dotnet sln SchoolManagement.sln add ./tests/SchoolManagement.Tests/SchoolManagement.Tests.csproj
# List projects in solution
dotnet sln SchoolManagement.sln list
# Remove project from solution
dotnet sln SchoolManagement.sln remove ./old/OldProject.csproj
dotnet tool — Global Tools
# Install EF Core tools (essential!)
dotnet tool install --global dotnet-ef
# Verify EF tools
dotnet ef --version
# Install other useful tools
dotnet tool install --global dotnet-aspnet-codegenerator
# List installed tools
dotnet tool list --global
# Update tool
dotnet tool update --global dotnet-ef
School Management — Full Project Setup
# 1. Create solution
mkdir SchoolManagementSystem && cd SchoolManagementSystem
dotnet new sln -n SchoolManagement
# 2. Create projects
dotnet new webapi -n SchoolManagement.Api -o src/Api
dotnet new classlib -n SchoolManagement.Core -o src/Core
dotnet new classlib -n SchoolManagement.Data -o src/Data
dotnet new xunit -n SchoolManagement.Tests -o tests/Tests
# 3. Add to solution
dotnet sln add src/Api/SchoolManagement.Api.csproj
dotnet sln add src/Core/SchoolManagement.Core.csproj
dotnet sln add src/Data/SchoolManagement.Data.csproj
dotnet sln add tests/Tests/SchoolManagement.Tests.csproj
# 4. Add project references
dotnet add src/Api reference src/Core/SchoolManagement.Core.csproj
dotnet add src/Api reference src/Data/SchoolManagement.Data.csproj
dotnet add src/Data reference src/Core/SchoolManagement.Core.csproj
dotnet add tests/Tests reference src/Core/SchoolManagement.Core.csproj
# 5. Add NuGet packages
cd src/Api
dotnet add package Microsoft.EntityFrameworkCore.SqlServer
dotnet add package Microsoft.AspNetCore.Authentication.JwtBearer
dotnet add package Swashbuckle.AspNetCore
# 6. Run
dotnet run --project src/Api
🤖Use AI to Learn Faster
Use ChatGPT, Claude, or Copilot to go deeper on dotnet CLI commands. Try these prompts:
"What are the most important dotnet CLI commands I will use every day as a .NET developer?""What is the difference between dotnet build and dotnet publish?""What is dotnet watch run and when should I use it?""Quiz me on dotnet CLI — ask 5 commands and I name what they do"
💡 Tip: After reading this article, paste your own code into AI and ask "What could go wrong here and why?" — fastest way to find edge cases and deepen understanding.
Next Article
nexcoding.in
Have questions on your tech stack, ongoing projects, or need one-to-one training?