Useful dotnet commands
Common CLI snippets for daily work.
Create a solution and add a project
bash
dotnet new webapi -o MyWebApi
dotnet new sln -o MySolution
cd MySolution
dotnet sln add ../MyWebApi/MyWebApi.csprojSelf-contained publish
bash
dotnet publish ../MyWebApi/MyWebApi.csproj -c Release -r win-x64 --self-containedList SDKs and runtimes
bash
dotnet --list-sdks
dotnet --list-runtimesRun
bash
dotnet run --environment Development
dotnet run --urls "http://*:5000;https://localhost:5001"
# localhost:5000 — local only
# 0.0.0.0:5001 — listen on all interfaces (e.g. Ubuntu server)
dotnet run -p ../MyWebApi/MyWebApi.csproj
dotnet run --verbosity detailedProjects & solutions
bash
dotnet new console -o MyConsoleApp
dotnet new classlib -o MyLibrary
dotnet new webapi -o MyWebApi
dotnet new blazorserver -o MyBlazorApp
dotnet new sln -o MySolution
dotnet sln add MyProject.csproj
dotnet sln remove MyProject.csproj
dotnet sln listBuild & run
bash
dotnet restore
dotnet build
dotnet build --configuration Release
dotnet runPublish
bash
dotnet publish -r win-x64 --self-contained
dotnet publish -r win-x64 --framework-dependentTests & packages
bash
dotnet test
dotnet test --filter MyTest
dotnet list package
dotnet list package --include-transitive
dotnet add package Newtonsoft.Json
dotnet remove package Newtonsoft.Json
dotnet add reference ../MyLib/MyLib.csprojSDK & environment
bash
dotnet --info
dotnet --list-sdks
dotnet --list-runtimes
dotnet help
dotnet --sdk-version 6.0.100 buildNuGet
bash
dotnet restore
dotnet nuget locals all --clear
dotnet pack
dotnet nuget push MyPackage.nupkg --source https://api.nuget.org/v3/index.jsonMisc
bash
dotnet msbuild /t:CustomTarget
dotnet build --verbosity detailed
dotnet interactive
dotnet build --performance-summary
dotnet tool run <tool-name>
dotnet run --sourceLinkDebug / perf
bash
dotnet run --aot
dotnet run --collect:Memory
dotnet publish -r win-x64 --self-contained -p:PublishSingleFile=true
dotnet run --no-build --framework net6.0