The ASP.NET Command Line Interface (CLI) provides a simple and efficient way to create new ASP.NET Core projects. This guide will walk you through the steps to create a new project using the CLI, including the necessary commands and explanations.

Prerequisites

Before you begin, ensure that you have the .NET SDK installed on your machine. You can verify the installation by running the following command in your terminal or command prompt:

dotnet --version

If the command returns a version number, you are ready to create a new project. If not, please install the .NET SDK first.

Step 1: Open Your Command Line Interface

Open your terminal (macOS/Linux) or command prompt (Windows). Navigate to the directory where you want to create your new project.

Step 2: Create a New Project

Use the dotnet new command to create a new ASP.NET Core project. The command syntax is as follows:

dotnet new <template> -n <ProjectName>

Here, <template> specifies the type of project you want to create, and <ProjectName> is the name of your project.

For example, to create a new ASP.NET Core web application, you would run:

dotnet new webapp -n MyWebApp

This command creates a new ASP.NET Core web application named MyWebApp in a folder with the same name.

Step 3: Navigate to the Project Directory

After creating the project, navigate into the project directory using the cd command:

cd MyWebApp

Step 4: Run the Application

To run your newly created ASP.NET Core application, use the dotnet run command:

dotnet run

After running this command, you should see output indicating that the application is running. By default, it will be accessible at http://localhost:5000 or https://localhost:5001.

Step 5: Open Your Web Browser

Open your web browser and navigate to http://localhost:5000 to see your new ASP.NET Core web application in action.

Available Project Templates

The dotnet new command supports various project templates. Here are some commonly used templates:

  • webapp: Creates a new ASP.NET Core Razor Pages application.
  • mvc: Creates a new ASP.NET Core MVC application.
  • api: Creates a new ASP.NET Core Web API application.
  • blazorserver: Creates a new Blazor Server application.
  • blazorwasm: Creates a new Blazor WebAssembly application.

Conclusion

Creating a new ASP.NET Core project using the CLI is a straightforward process that allows developers to quickly scaffold applications. By following the steps outlined above, you can set up a new project and start building your web applications efficiently. The CLI provides a powerful way to manage your projects and streamline your development workflow.