Getting Started With ASP.NET Core - Part Three

This article explains about the ASP.NET core Basic, Project modification, Advance commands and create, build and run the console application using CLI commands.

Introduction

 
Please read the whole ASP.NET Core series using the below links of the previous articles before reading this one.
Definition
 
ASP.NET Core is a cross-platform and open-source framework. ASP.NET Core supports Windows, Mac or Linux operation system. It is used for developing modern, cloud-based, and high-performance web applications.
 

ASP.NET Core CLI Commands

 
ASP.NET Core command-line interface is a cross-platform tool for creating and restoring packages for building, running and publishing ASP.NET Core application.
 
ASP.NET Core Command Line Interface is installed with .NET Core SDK so we do not need to install these separately for developing the application. Read the first part of this article using the above link, which explains how to install .NET Core SDK for development.
 
We can verify whether CLI is installed or not using the command prompt. Open the command prompt and type “dotnet” and press Enter. We will be getting the output like the below screenshot.
 
Getting Started With ASP.NET Core
 
If we entered the wrong command or did not install the CLI, then we will get the error like below.
 
Getting Started With ASP.NET Core
 
We can get help for all commands through .NET Core CLI. If using “dotnet --help” command, we can get the list of all commands.
Type “dotnet --help” and press Enter in the command prompt.
 
Getting Started With ASP.NET Core
 
There are the following three different types of commands in ASP.NET Core.
  1. Basic Commands
  2. Project Modification Commands
  3. Advanced Commands

Basic Commands

 
Basic commands are very important commands in ASP.NET Core and we are using basic commands often. There are following commands available in the basic commands.
 
Getting Started With ASP.NET Core
 

Project Modification Commands

 
We can add and remove the packages, references and list all project references so we can modify our projects using the following commands simply.
 
Getting Started With ASP.NET Core
 

Advanced Commands

 
Advanced commands are used for delete, clear, push, build, and install the script in the out application. Those commands are using at the advanced level. The following commands are used.
 
Getting Started With ASP.NET Core
 

Creating New Project Using .NET Core CLI Commands

 
We are going to create the new ASP.NET Core application using .NET Core CLI Commands step by step.
 
Step 1
 
First, choose your application path that where we are going to save the application. Go to your path in the command prompt.
 
Getting Started With ASP.NET Core
 
Step 2
 
Check the .NET Core CLI command is whether working or not. We can check using “dotnet” command in the specified path.
 
Getting Started With ASP.NET Core
 
Step 3
 
Type the “dir” in the specified path in the command prompt and check the count of files and its size. Now we do not have any files in the directory.
 
Getting Started With ASP.NET Core
 
Step 4
 
We are going to create the console application using CLI command. Creating a new console using CLI so type “dotnet new console” command in the command prompt. Before creating the new console, we need to know about “new” command so type “dotnet new -h” then we will get the detailed description with the new command for creating a different type of application.
 
Getting Started With ASP.NET Core
 
Getting Started With ASP.NET Core
 
We are going to create a Console Application. Console supports the C#, F#, and VB languages and it tags Common/Console. Now create the console application using CLI command “dotnet new console”
 
Getting Started With ASP.NET Core
 
Once you run the above command you'll get the message  “The template ‘Console Application’ was created successfully”. After creating the console application restore command will execute automatically for restoring the dependencies and tools of a project.
 
Step 5
 
We can check the count and size files in the specified directory. Again type “dir” command for checking the file count and size.
 
Getting Started With ASP.NET Core
 
Step 6
 
We are going to run the console application which we have created. Type “dotnet build” in the command prompt to build the application. We will get the below message after building the console application successfully.
 
Getting Started With ASP.NET Core
 
We are going to run the application using “dotnet run” after building the application successfully. Once we run the application, we are getting the output that looks like the below screenshot.
 
Getting Started With ASP.NET Core
 
Step 7
 
We can edit the code using any IDE (Integrated Development Environment) like Visual Studio Code, Visual Studio, Notepad++ or Notepad.
 
We can open the class file using the command “notepad FileName.Extension .”, for example, type the command in the specified path like “notepad Program.cs .” and press enter then “Program.cs” file will open in notepad file.
 
Getting Started With ASP.NET Core
 
We can open the entire console application in Visual Studio Code using the command “code .”.
 
Getting Started With ASP.NET Core
 
We can open the console application from the Visual Studio. Go to file choose the application location and open the console application.
 
Getting Started With ASP.NET Core
 

Conclusion

 
This article explained ASP.NET core basic project modification, advanced commands, and how to create, build and run the console application using CLI commands. I hope this really helps new learners, students, and freshers.