In this article, I am going to explain how we will learn about the .NET Core command-line interface that is CLI. Please, read our previous article before proceeding to this article where we understand the Installing & Setting Up ASP.NET Core Development Environment.
Now, As part of this article, we are going to discuss the following five things.
1. What is CLI?
2. What all is possible with the .NET CLI?
3. What is the CLI driver?
4.Command, Argument, Option
5..NET CLI commands demonstration
So, basically we are going to show a few commands of the .NET CLI. Now before learning about the .NET Core CLI.
Let’s understand what is a CLI. the CLI stands for command-line interface CLI is an interface. that uses to interact with a program.
So, everything which is possible with the CLI, you can do with the help of GUI as well if you think about the visual studio. then everything which is available in the CLI is available as a GUI.
Basically, the visual studio is the GUI which is the graphical interface and CLI is the command-line interface. so there are two separate things if you need to work with the .NET Core program then there are two ways to work with that program.
1. Graphical User Interface
2. Command-line interface
So, the CLI each language provides its own CLI to interact with the program. if you think about the angular when angular has its own CLI which is ng if you need to work with any kind of command of the angular. then you can use angular CLI if you are working with a .NET Core code then we dotnet cli. If you are working in the PHP then similarly we have a CLI for the PHP it means almost all the language has its own CLI.
Download Dotnet CLI
The .NET CLI is s part of the Net Core SDK installation. You can download the Net Core SDK from the link. https://dotnet.microsoft.com/download
The .Net CLI installs step by step manner. So many versions of CLI Tools can be installed and used.
Let’s check our .NET CLI command on command prompt Before, the installation of .Net Core SDK.
.Net Core SDK installation
After the successful installation of the .NET SDK. Let’s check the command-line.
Using Dotnet CLI
The syntax of .NET CLI consists of three parameters. The first is the driver, the second is “verb”, and the last is “arguments”.
dotnet [verb] [arguments]
The driver is named “dotnet”
The “verb” is the command that we want to execute. Then the command performs an action. After, the “arguments” are passed to the commands invoked.
Commonly used Commands
Here are some of the commands uses commonly for the dotnet
It creates a new project, solution based on the specified template or configuration file.
It Restores the dependencies and tools of a project.
It Builds the project and all its dependencies.
It packs the application and its dependencies into the folder for deployment to a hosting system.
It Runs source code without any explicit compile or launch commands.
.NET test driver used to execute unit tests.
It runs tests from the specified files.
It packs the code into a NuGet package.
It migrates the Preview 2 .NET Core project to a .NET Core SDK 1.0 project.
Cleans the output of a project.
It modifies the .NET Core solution file.
It shows the more detailed documentation online for the specified command.
It stores the specified assemblies in the runtime package store.
Creating a new ASP.NET Core Web Application using dotnet CLI
Let’s, Open the windows command prompt and create a Folder named “HelloWorld”.
So, the dotnet new command uses to create a new project. The partial syntax is as follows.
> dotnet new <TEMPLATE> [--force] [-i|--install] [-lang|--language] [-n|--name] [-o|--output]
The template to instantiate when the command invokes.
It forces the content to generates even if it would change existing files. so, This requires when the output directory already contains a project.
So, it Installs a source or template pack from the PATH or NUGET_ID provided.
the lists of the templates are containing to the specified name. If it invokes the dotnet new command, it provides the lists of possible templates available for the given directory. below example, if the directory already exists a project. it doesn’t list all project templates.
We need to assign the language to the template for creating. so, the language accepted varies by the template. Not valid for some templates.
So, the name for the generated output. If no name identifies, the name of the current directory uses.
Now, location to place the generated output. The default is the current directory.
It prints out help for the command.
So, the complete list of options for dotnet new is available here.
Create a New Project using dotnet new
The below command creates a new dotnet project using the TEMPLATE.
> dotnet new <TEMPLATE>
You can get the list of the template using the following command.
> dotnet new -l
List of Templates
TEMPLATE DESCRIPTION console Console Application classlib Class library mstest Unit Test Project xunit xUnit Test Project web ASP.NET Core Empty mvc ASP.NET Core Web App (Model-View-Controller) razor ASP.NET Core Web App angular ASP.NET Core with Angular react ASP.NET Core with React.js reactredux ASP.NET Core with React.js and Redux webapi ASP.NET Core Web API
if we want to create an empty web application use the template web.
> dotnet new web
Running the Application using dotnet run
Use dotnet run command to start the application and see the output on browser localhost.
Restoring the Dependencies with dotnet restore
After the new project created, we have to download the dependencies. This is done using the restore command.
> dotnet restore
use –help to get help
> dotnet restore --help
Thank you for reading this article, I hope you will understand the Dotnet CLI Command line tool for ASP.NET Core. We’ll get into more details about this when we’ll learn CRUD Operations With ASP.NET Core MVC Using ADO.NET in the next article.