Boosting Your Productivity with .NET Core CLI Commands

Introduction

In this article, I am going to explain how to boost your productivity with.net core CLI Commands and how to use .NET Core CLI (Command Line Interface) commands that will help developers speed up their work using a few tips and tricks. Using the.Net CLI, we can create, build, add packages, restore packages, run applications, and deploy Core applications. I will cover essential commands like creating new projects, compiling and running applications, managing dependencies, and handling NuGet packages.

Boosting Productivity with Visual Studio's Command Line Interface

When we create any new application using Visual Studio, it's internally using  .Net CLI commands to create, build, add packages, run, and deploy applications. 

Note. By default, the.NET Core CLI is also installed when you install the.NET Core SDK. So we do not require any separate installation to use .Net Core CLI.

How to check whether .Net CLI is installed or not?

Open Run, then type CMD.

CMD

Once the command prompt is open, Type dotnet and hit enter.

CMD Mocrosoft windows

Syntax to run CLI Command : dotnet <command> <argument> <option>

Note. All commands start with dotnet. The above syntax will help developers execute required commands from the command-line interface. Let's use the first Command to get help for all commands (dotnet help).

How do I get a list of all.Net Core commands?

.Net Core Commands

List of all .Net Core commands

Below is a list of all .Net core commands that will appear once we run the "dotnet help" command. Let's list down all commands as below with a short description of what each does.

SDK commands

  1. add:  Add a package or reference to a .NET project
  2. build: Build a .NET project
  3. build-server: Interact with servers started by a build
  4. clean: Clean build outputs of a .NET project
  5. format: Apply style preferences to a project or solution
  6. help: Show command line help
  7. list: List project references of a .NET project
  8. msbuild: Run Microsoft Build Engine (MSBuild) commands.
  9. new: Create a new .NET project or file.
  10. NuGet: Provides additional NuGet commands.
  11. pack: Create a NuGet package.
  12. publish: Publish a .NET project for deployment
  13. remove: Remove a package or reference from a .NET project.
  14. restore: Restore dependencies specified in a .NET project.
  15. run: Build and run a .NET project output.
  16. SDK: Manage .NET SDK installation.
  17. sln: Modify Visual Studio solution files.
  18. store: Store the specified assemblies in the runtime package store.
  19. test: Run unit tests using the test runner specified in a .NET project.
  20. tool: Install or manage tools that extend the .NET experience.
  21. vstest:  Run Microsoft Test Engine (VSTest) commands.
  22. workload: Manage optional workloads.

How to create a new console project?

Let's create a new console project using the "dotnet new" Command.

dotnet new console -n MyConsoleAppUsingCLI -o C:\Users\XXXXX\projects\MyConsoleAppUsingCli

 "dotnet new" command

Once the above Command runs successfully, We are able to create a console application with the name "MyConsoleAppUsingCli" at the given path "C:\Users\XXXXX\projects\". Let's build the newly created project using the build command.

Build Command: dotnet build C:\Users\Jigs\projects\MyConsoleAppUsingCli\

Build command

Once we run the build command, As per the above screen, the project build succeeded.

How to add a package reference to the new console application?

Let's add a package reference to the new console application using the add package CLI command.

We have added the package "Microsoft.EntityFrameworkCore" to our project. Let's open our console app in Visual Studio and check the newly added package reference in the solution.

As per the above screen, We are able to see Microsoft.EntityFrameworkCore package reference was added successfully.

Run the project using Run CLI Command

Run project using Run CLI Command: dotnet run --project C:\Users\Jigs\projects\MyConsoleAppUsingCli\MyConsoleAppUsingCli.csproj

Run cli command

Summary

In this article, I have demonstrated how to boost productivity with Visual Studio's command-line interface. CLI is very powerful and is used for developing, running, and publishing applications. We have covered essential commands like creating new projects, compiling and running applications, managing dependencies, and handling NuGet packages in console applications. Here I have explained the basic commands required to set up a project and run the new project, but you can explore more on other commands and leverage the power of the.NET Core CLI for streamlined and productive development projects.

If you want to explore my .net core other articles, please refer here,


Similar Articles