The dotnet CLI is the Swiss Army knife for .NET development. It’s cross-platform, consistent, and handles everything from scaffolding a project to deploying it to production.

🏗️ Project Creation & Management

These commands help you get a project off the ground and manage its structure.

Command Description
dotnet new list List all available project templates (console, webapi, blazor, etc.).
dotnet new <TEMPLATE> Create a new project based on a template (e.g., dotnet new console).
dotnet new sln Create a new empty solution file.
dotnet sln add <PROJECT> Add a project to the solution file.
dotnet new gitignore Generate a standard .gitignore file for .NET projects.

🛠️ Build, Run, & Debug

The core workflow for everyday development.

  • dotnet restore: Downloads dependencies and NuGet packages defined in the project file. (Note: Most commands like build run this automatically).
  • dotnet build: Compiles the project into binaries (.dll or .exe).
  • dotnet run: Builds (if necessary) and runs the application.
    • Tip: Use dotnet run --project <PATH> if you aren’t in the project directory.
  • dotnet watch: Restarts or hot-reloads the application when it detects file changes. Perfect for web development.
  • dotnet clean: Cleans the build output (removes the bin and obj folders).

📦 Package Management (NuGet)

Use these to manage external libraries without manually editing .csproj files.

  • dotnet add package <PACKAGE_NAME>: Adds a NuGet package to the project.
  • dotnet remove package <PACKAGE_NAME>: Removes a NuGet package.
  • dotnet list package: Lists all packages installed in the project.
  • dotnet add reference <PROJECT_PATH>: Adds a project-to-project reference.

🧪 Testing

Commands for running unit tests and checking code quality.

  • dotnet test: Runs tests using the configured test runner (xUnit, NUnit, or MSTest).
  • dotnet test --filter “ClassName=MyTests”: Runs specific tests based on a filter.
  • dotnet test --logger “console;verbosity=detailed”: Gets more verbose output during test runs.

🚀 Deployment & Distribution

When you’re ready to ship your code.

  • dotnet publish -c Release: Packs the application and its dependencies into a folder for deployment.
  • dotnet publish -r <RID> --self-contained: Publishes a self-contained executable for a specific Runtime Identifier (e.g., win-x64, linux-x64).
  • dotnet pack: Creates a NuGet package (.nupkg) from your code.

🔍 Tools & Diagnostics

  • dotnet --info: Displays detailed information about your .NET installation (SDKs, Runtimes, etc.).
  • dotnet tool install -g <TOOL_NAME>: Installs a global tool (like dotnet-ef for Entity Framework).
  • dotnet dev-certs https --trust: Generates and trusts a local HTTPS development certificate.

Pro Move: Almost every command accepts the -h or --help flag. If you forget the syntax for a specific command, just run dotnet <command> --help.