Asp.NET Core Command Line

Asp.NET Core Command Line

Asp.NET Core Command Line


Dotnet CLI is a command line tool. It contains commands you can use to
1. Create a new project
2. Build a project
3. Run the project
4. Publish the project
5. Restore Nuget Packages
6. Migrate from one version to another version of .NET

Download & Installing dotnet cli
The Dot Net CLI is part of the .NET SDK. Hence install .NET SDK to install the .NET CLI.
The CLI installs side by side manner. We can install & use multiple versions of CLI Tools side by side.

Commonly used Commands
new- Creates a new project, configuration file, or solution based on the specified template.

dotnet new <TEMPLATE> [--force] [-i|--install] [-lang|--language] [-n|--name] [-o|--output]
// TEMPLATE - The project template to use when we invoke the command.
// –force - Forces content to be generated even if it would change existing files.
This is required when the output directory already contains a project.
// -i|–install <PATH|NUGET_ID> - Installs a source or template pack from the PATH or NUGET_ID provided.
// -l|–list - 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.
// -lang|–language {C#|F#|VB} - 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.
// -n|–name <OUTPUT_NAME> - The name for the created output. If we do not specify the name, it will use
the name of the current directory.
// -o|–output <OUTPUT_DIRECTORY> - Location to place the generated output. The default is the current directory.

Dotnet new -l   - find out the list of template using
// 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

restore- Restores the dependencies and tools of a project.
build- Builds a project and all of its dependencies.
publish- 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.

dotnet add package Newtonsoft.json // This will add the Newtonsoft.json package to your project
dotnet remove package Newtonsoft.json // Remove the 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.

Some of the key functionalities and tasks that the ASP.NET Core CLI supports:
Creating Projects: Using templates, you can use the CLI to create new ASP.NET Core projects. For example, you can create a new web application, a web API, a class library, and more.
Building Projects: The CLI allows you to build your projects using the dotnet build command. This compiles your code, resolves dependencies, and produces the output binaries.
Running Applications: You can execute your ASP.NET Core applications using the dotnet run command. This starts your application and hosts it on a local development server (usually Kestrel).
Publishing Applications: The dotnet publish command packages your application for deployment. It compiles the code, includes all required dependencies, and prepares the output for deployment to a server.
Adding Packages: The CLI supports adding NuGet packages to your project using the dotnet add package command.
Managing Dependencies: Using the CLI, you can manage package references, remove packages, and update package versions.
Database Migrations: For projects that use Entity Framework Core, the CLI can be used to manage database migrations and apply changes to the database schema.
Global Tools: The CLI allows you to install and manage global tools that provide additional functionality, like code analysis or project scaffolding.
Project Scaffolding: The CLI can generate code files and project structures based on templates.
Testing: You can run unit tests using the dotnet test command.
Code Generation: The CLI supports code generation for various parts of your application, such as controllers, views, and more.

Related Post

About Us

Community of IT Professionals

A Complete IT knowledgebase for any kind of Software Language, Development, Programming, Coding, Designing, Networking, Hardware and Digital Marketing.