Introduction
CLI (Command Line Interface) is new cross-platform tool for developing .NET Core applications. It is also referred to as a foundational tool because it is a primary layer on which other tools like IDE (Integrated Development Environments) build the application and run it.
CLI tools are available in DEB packages for Ubuntu and MSI bundles for Windows. This installer will install the tool and setup the environment required to run CLI tool. There is a possibility of multiple versions of CLI tools installed on a single machine.
All CLI commands are run from command prompt. The CLI command mainly contains three parts -
- The driver
- Command
- Command Argument

Driver
The verb "dotnet" is used as driver. The following two are the primary responsibilities for the driver.
- Executing IL (Intermediate Language) code
- Executing the Command
The driver is responsible to find out the version of the tool that we want to use. We can specify the version of the tool in "sdkVersion" property of "global.json" file. If the specified version of CLI tool is not available, driver uses the latest version of the tools that are available. The driver will start to execute the command once the tool version is found.
Command
The command is the action which needs to be performed by the driver. For example, "dotnet new" will create new project for us.
Arguments
The arguments are passed with the command. The arguments are the helping hand of the command and they provide required user input to the command. For example, "dotnet run --project /myprojects/project.json" runs project under specified folder.
Built-in supported Commands
Following commands are installed with default installation.
- new
- restore
- run
- build
- test
- publish
- pack
CLI tool provides the way to import more commands on the basis of need in project. We can add our own command as well.
“dotnet” command
The dotnet is a generic driver for the CLI tool and it is used to run the command-line commands. The dotnet is itself used as command; and with this command, it has the following options.
| Options | Description |
| --version | Display the current version of the CLI tool |
| -v or --verbose | Enables verbose output |
| --info | Display more details about the CLI tool like name and version of the OS, SHA-1 information etc. |
| --help or-h | Display short help and list down current supported command |
Example
I have run the following commands in command window
>dotnet --version
>dotnet --info
>dotnet –v
>dotnet --help
Outputs

"dotnet new" command
It is used for creating new .NET core project. It provides convenient way to initialize a valid .NET Core project and sample source code. When we run this command, two main files will be created - Program.cs and Project.json. We can edit these files as per our requirement.
Syntax
dotnet new [arguments/options]
| Options | Description |
| -l Or --lang | Create specified language project in current directory. Currently it able to create C# and F# project |
| -tor --type | Create specified type of project in current directory. The supported values are console, web, lib and xunittest |
Examples
I have run the following commands in command window.
>dotnet new
>dotnet new -l F#
>dotnet new - t web
Output

"dotnet restore" command
This command is use to restore the dependencies to the project. It uses NuGet to restore dependencies which are specified in project.json file. Dependencies restorations are done parallelly.
The configuration file "NuGet.config" provides the feeds where packages are located. When we installed CLI tools, by default one feed is present. We can specify more feeds by creating our own NuGet.config file in the project directory.
Syntax
dotnet restore [arguments/options]
| Options | Description |
| -s Or –source [Source] | Used to specify a source during the restore operation. This will overrides all sources specified by in nuget.config files. |
| --packages [DIR] | Specified the directory to restored packages placed in. |
| --disable-parallel | Using this command we can disables restoring multiple projects in parallel. |
| -f Or --fallbacksource [FEED] | It used to specify a fallback source which can be use in restore operation if main source is failing to restore |
| --configfile [FILE] | Specify the configuration file NuGet.config that is used to perform restore operation. |
| --verbosity [LEVEL] | Specify which level of logging to use. Available options are Debug, Verbose, Information, Minimal, Warning and Error. |
Example
I have run the following commands in command window.
>dotnet restore -s “D:\packages”
>dotnet restore --packages “Mypackages”
Output

"dotnet build" command
It builds a project and its dependencies. It builds multiple source files from the project and its dependencies into binary and binary is in IL (Intermediate Language) and it has a DLL extension. This command requires lock file to be present in current directory, it means that we must run "dotnet restore" command prior to building a command.
Syntax
>dotnet build [arguments/options]
| Options | Description |
| -o Or --output [DIR] | Build binaries are placed into specified directory. |
| -b Or --build-base-path [DIR] | Temporary outputs are created in specified directory. |
| -f Or --framework [FRAMEWORK] | Build compiles for the specific folder. |
| -c Or --configuration [Debug|Release] | Define the build configuration. Default value of configuration is "Debug". |
| -r Or --runtime [RUNTIME_IDENTIFIER] | Define the target runtime to build. |
| --version-suffix [VERSION_SUFFIX] | It defines what would be replaced with the version field in to the project.json file. |
| --build-profile | It defines the incremental safety check which user needs to turn on automatically incremental compilation. |
| --no-incremental | This will mark the build as unsafe for incremental build. It turns off incremental compilation and forces rebuild of project dependency graph |
| --no-dependencies | Only build the root project and ignore the build reference project. |






Join the conversation! Your thoughts help the community grow.