.NET CLI Tools
The .NET Command Line Interface (CLI) is a cross-platform toolchain that allows you to create, build, test, and publish .NET applications. It's an essential part of the modern .NET development workflow.
Core Commands
Here are some of the most frequently used .NET CLI commands:
Creating Projects and Solutions
dotnet new
: Creates a new .NET project or solution from a template.dotnet new list
: Lists available project templates.dotnet new install
: Installs a new template pack.
Example of creating a console application:
dotnet new console -o MyConsoleApp
Building and Running Applications
dotnet build
: Compiles a project.dotnet run
: Compiles and runs a project.dotnet clean
: Cleans the project output.dotnet publish
: Publishes a .NET application for deployment.
Example of running an application:
dotnet run --project ./MyConsoleApp/MyConsoleApp.csproj
Managing Dependencies
dotnet add package
: Adds a NuGet package to the project.dotnet remove package
: Removes a NuGet package from the project.dotnet restore
: Restores project dependencies.
Example of adding a package:
dotnet add package Serilog --version 2.10.0
Testing Applications
dotnet test
: Runs unit tests in a project.
Example of running tests:
dotnet test ./MyProject.sln
Other Useful Commands
dotnet --version
: Displays the .NET CLI version.dotnet --info
: Displays detailed information about the .NET installation.dotnet pack
: Creates a NuGet package from a library project.dotnet sln
: Manages solution files.
Getting More Help
For a complete list of commands and detailed options, you can use the built-in help system:
dotnet --help
Or, visit the official Microsoft .NET CLI documentation.