dotNet Commands
Here is a list of common dotnet
commands used for managing .NET projects and solutions:
General Commands
dotnet --version
Displays the version of the .NET SDK installed.
dotnet --info
Displays information about the installed .NET SDKs and runtimes.
dotnet new --list
Lists all available templates for creating new projects.
Creating a New Project
dotnet new <template>
Creates a new project or file using the specified template. Examples:
dotnet new console
- Creates a new console application.dotnet new mvc
- Creates a new ASP.NET Core MVC web application.dotnet new classlib
- Creates a new class library.
dotnet new <template> -n <name>
Specifies a name for the new project. Example:dotnet new console -n MyApp
Building and Running
dotnet build
Builds the project.
dotnet run
Runs the application (for executable projects).
dotnet publish
Publishes the application for deployment.
Adding and Managing Dependencies
dotnet add package <package-name>
Adds a NuGet package to the project. Example:
dotnet list package
Lists the NuGet packages installed in the project.
dotnet remove package <package-name>
Removes a NuGet package from the project.
Project Management
dotnet sln <solution.sln> add <project.csproj>
Adds a project to a solution file.
dotnet sln <solution.sln> remove <project.csproj>
Removes a project from a solution file.
dotnet clean
Cleans the build output.
Testing
dotnet test
Runs tests in the project.
Tool Management
dotnet tool install -g <tool-name>
Installs a global tool.
dotnet tool list --global
Lists all globally installed tools.
dotnet tool uninstall -g <tool-name>
Uninstalls a global tool.
Miscellaneous
dotnet watch run
Watches for file changes and automatically rebuilds and reruns the application.
dotnet format
Formats the code in the project according to style rules.
If you need specific examples or details about any command, let me know!