The dotnet CLI is a command-line interface (CLI) is a new tool for developing the .NET application. It is a cross-platform tool and can be used in Windows, MAC or Linux. In this tutorial, we will learn how to use .NET Cli create a simple ASP.NET Core application
Table of Content
Dotnet CLI download
The Dot Net CLI is installed as part of the Net Core SDK. You can download the Net Core SDK from this link
The CLI installs side by side manner. So multiple versions of CLI Tools can be installed and used
Using Dotnet CLI
The syntax of Dotnet CLI consists of three parts. The driver, the “verb”, and the “arguments”
dotnet [verb] [arguments]
The driver is named “dotnet”
The “verb” is the command that you want to execute. The command performs an action
The “arguments” are passed to the commands invoked
Commonly used Commands
Here are some of the commonly used commands for the dotnet
|new||Creates a new project, configuration file, or solution based on the specified template.|
|restore||Restores the dependencies and tools of a project.|
|build||Builds a project and all of its dependencies.|
Packs the application and its dependencies into a folder for deployment to a hosting system.
|run||Runs source code without any explicit compile or launch commands.|
|test||.NET test driver used to execute unit tests.|
|vstest||Runs tests from the specified files.|
|pack||Packs the code into a NuGet package.|
|migrate||Migrates a Preview 2 .NET Core project to a .NET Core SDK 1.0 project.|
|clean||Cleans the output of a project.|
|sln||Modifies a .NET Core solution file.|
|help||Shows more detailed documentation online for the specified command.|
|store||Stores the specified assemblies in the runtime package store.|
Creating a New ASP.NET Core project using dotnet CLI
Open the command prompt or Windows Powershell and create a Folder named “HelloWorld”
dotnet new command is used to create the 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 is invoked
Forces content to be generated even if it would change existing files. This is required when the output directory already contains a project.
Installs a source or template pack from the PATH or NUGET_ID provided.
Lists templates containing the specified name. If invoked for the dotnet new command, it lists the possible templates available for the given directory. For example, if the directory already contains a project, it doesn’t list all project templates.
The language of the template to create. The language accepted varies by the template (see defaults in the arguments section). Not valid for some templates.
The name for the created output. If no name is specified, the name of the current directory is used.
Location to place the generated output. The default is the current directory.
Prints out help for the command
The complete list of options for dotnet new is available here
Create a New Project using dotnet new
The following command creates a new dotnet project using the TEMPLATE
dotnet new <TEMPLATE>
You can find out the list of template using
Dotnet new -l
List of Templates
|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|
To create an empty web application use the template web
Dotnet new web
Restoring the Dependencies with dotnet restore
Once we created the new project, we have to download the dependencies. This is done using the restore command
use –help to get help
Dotnet restore --help
Running the Application with dotnet run
Use dotnet run to start the application
Open localhost:5000/ in the browser and you should be able to see “Hello World”
We learned how to make use of dotnet CLI ( command-line interface). This tool is useful in MAC /Linux where IDE Like Visual studio is not available.