Important .NET CLI commands
While working with .NET Core, it sometimes makes your life easy if know a few important .NET CLI commands.
Ankush Jain
Lead Software Engineer (VP) | Software Architect
While working with .NET Core, it sometimes makes your life easy if know a few important .NET CLI commands.
Here are some of the most commonly used .NET CLI commands.
General
// To check current .NET infodotnet --info
// To check installed SDKsdotnet --list-sdks
// To check installed runtimesdotnet --list-runtimesRestore
// To restore NuGet packagesdotnet restoreImplicit restore
You don't have to run dotnet restore because it's run implicitly by all commands that require a restore to occur, such as dotnet new, dotnet build, dotnet run, dotnet test, dotnet publish, and dotnet pack. To disable implicit restore, use the --no-restore option.
Create
// To create a new dotnet applicationdotnet new <template> --output <output-directory>
// To create a new console applicationdotnet new console --output sample1
// To create a new web applicationdotnet new webapp -o aspnetcoreappBuild
// To build a solutiondotnet build solution.sln -c "Debug"
// To build a projectdotnet build project.csproj -c "Debug"Publish
// To publish an applicationdotnet publish -c "Release"
// To publish a projectdotnet publish "AccountingSoftware.API" -c "Release" -f "net6.0" --self-contained falseHow does dotnet publish work
dotnet publish compiles the application, reads through its dependencies specified in the project file, and publishes the resulting set of files to a directory.
Run
// To run published app directlydotnet MyApp.dll
// To run an application in debug modedotnet run [--project sample1] [--launch-profile "launch-profile-name"]How does dotnet run work
- It first builds the project using
dotnet buildand then runs the app from the output directorybin/debug/netcoreapp3.1/MainApp.dll - It uses a launch-profile to run the project.
- So command
dotnet run=dotnet build+ execute launch-profile command
How to debug apps running with dotnet run command
- To debug the app running in debug mode, use Attach to process in Visual Studio, and select the process with the name
AssemblyName.exe.
That's all 🙂