The .NET CLI (Command-Line Interface) is a powerful tool that lets you create, build, run, and manage .NET projects right from your terminal. Whether you’re a beginner or a seasoned developer, mastering the CLI will make you faster, more productive, and able to automate common tasks with ease.

This article will walk you through the most useful .NET CLI commands, explain what they do, and show you how to use them with clear, beginner-friendly examples.

Introduction to the .NET CLI

The .NET CLI is a cross-platform tool that works on Windows, macOS, and Linux. It comes with the .NET SDK and is available as the dotnet command in your terminal or command prompt.

Setting Up the CLI

  • Make sure you have the .NET SDK installed.
  • Open your terminal (Command Prompt, PowerShell, or Terminal on macOS/Linux).
  • Type dotnet --version to check your installation.

If you see a version number, you’re ready to go!

Project Management Commands

These commands help you create, build, and run .NET projects.

Create a New Project

This creates a new console application in a folder called MyApp.

Build Your Project

Compiles your code and checks for errors.

Run Your Application

Builds (if needed) and runs your application.

Restore Dependencies

Downloads and installs any NuGet packages your project needs.

Package Management with CLI

You can add, remove, and update NuGet packages directly from the CLI.

Add a Package

Adds the popular Newtonsoft.Json package to your project.

Remove a Package

Removes a package from your project.

List Installed Packages

Shows all NuGet packages currently installed in your project.

Useful Advanced Commands

Run Unit Tests

Discovers and runs tests in your project (using xUnit, NUnit, or MSTest).

Publish for Deployment

Builds your app for release and puts the output in the ./publish folder—ready for deployment.

Global Tools

Installs a global tool (like Entity Framework CLI) for use in any project.

Troubleshooting and Tips

  • Use dotnet --help or dotnet [command] --help to see all available options.
  • Use tab completion in your terminal to speed up typing commands.
  • Keep your .NET SDK up to date for the latest features and bug fixes.
  • Use dotnet clean to remove old build files if you run into strange errors.

Summary

The .NET CLI is your Swiss Army knife for .NET development. With just a few commands, you can create, build, run, test, and deploy your applications—no mouse required! The more you use the CLI, the more productive and confident you’ll become as a .NET developer.


This article is part of our .NET Essentials series. Next up: What is NuGet – learn how to manage dependencies and packages in your .NET projects.