Dotnet Cli Cheatsheet

Written by Eddie ZhangatDecember 20, 2024
snippets
dotnet

I prefer typing commands over clicking (blame VSCode for that).

General Workflow

# List all templates provided by Microsoft
dotnet new list <template name> --tag=<tag>
# For template names with spaces, please use double quotes
# Or search for a template on NuGet
dotnet new search <template name> --tag=<tag>
# Create a new application using the template's short name
dotnet new <template short name>

Unlike other CLI tools, the dotnet CLI creates files and folders directly in your current directory, so make sure to create a directory first before running this command.

# Run the application (navigate to the project folder first)
dotnet run
# Build the application
dotnet build

.NET SDK Commands

# List all SDK versions installed on your machine, The command structure differs from the usual pattern
dotnet --list-sdks
 
# Check current SDK version
dotnet --version

You can download SDKs from the official .NET download page

Alternatively, use the .NET SDK extension in VSCode as shown below: dotnet-install-tool

SDKs are installed globally, and the CLI automatically uses the latest version.

How to Switch SDK Versions

# Navigate to your project root and run:
dotnet new globaljson

This command works for both new and existing projects