Creating ASP.NET Core Web Application using Visual Studio

Creating ASP.NET Core Web Application using Visual Studio

In this article, I will discuss How to Create the ASP.NET Core Web Application using Visual Studio 2022 and .NET 6. Please read our previous article discussing the Differences Between .NET Core and .NET Framework.

Creating the First ASP.NET Core Web Application using Visual Studio 2022 and .NET 6

In this demo, we will create the ASP.NET Core Application using .NET 6. To create a new ASP.NET Core Application using .NET 6, open Visual Studio 2022 and click the Create a new project box, as shown in the image below.

Creating the First ASP.NET Core Web Application using Visual Studio 2022 and .NET 6

Once you click on the Create a new project box, the “Create a new project” window will open. This window includes different .NET 6 application templates. Here, we will create a simple Web application from scratch, so select the ASP.NET Core Empty project template and click the Next button, as shown in the image below.

Creating ASP.NET Core Web Application using .NET 6

Once you click on the Next button, it will open the following Configure Your New Project window. Here, you need to provide the necessary information to create a new project. First, give an appropriate name for your project (FirstCoreWebApplication), set the location where you want to create this project, and the solution name for the ASP.NET Core Web application. And finally, click on the Create button, as shown in the image below.

Creating ASP.NET Core Web Application using .NET 6

The Additional Information window will open once you click on the Next button. Here, you need to select .NET 6.0 as the Framework, check the Configure for HTTPS, and do not use top-level statements check boxes. Finally, click the Create button, as shown in the image below.

How to Create the ASP.NET Core Web Application using Visual Studio 2022 and .NET 6

Once you click on the Create button, it will create a new ASP.NET Core Web Application in Visual Studio 2022 using .NET 6. Wait for some time till Visual Studio restores the packages in the project. The restoring process means Visual Studio will automatically add, update, or delete configured dependencies as NuGet Packages in the project. The project will be created with the following file and folder structure in Visual Studio 2022. The major change you can see here is that we no longer have the Startup class, which we found in the earlier version of ASP.NET Core Framework.

How to Create the ASP.NET Core Web Application using Visual Studio 2022 and .NET 6

Run ASP.NET Core Application:

To run this ASP.NET Core Web Application, click on IIS Express or press F5 (with debugging) or Ctrl + F5 (without debugging). This will open the browser and display the following output.

Run ASP.NET Core Application

Here, the output “Hello World!” comes from the Main method of the Program class, which is present inside the Program.cs file, as shown in the below image.

Run ASP.NET Core Application

Now, open the Program.cs class file and change the “Hello World!” string to something else, as shown in the code below. Rerun the application, and it will change the output accordingly.

namespace FirstCoreWebApplication
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var builder = WebApplication.CreateBuilder(args);
            var app = builder.Build();

            app.MapGet("/", () => "Welcome to .NET 6");

            app.Run();
        }
    }
}
Project Templates in ASP.NET Core 6

As you can see in the image below, while creating an ASP.NET Core Application, we have different types of project templates for creating ASP.NET Core Web applications.

Project Templates in ASP.NET Core 6

Let us understand what all these project templates and their use are.

  1. ASP.NET Core Empty: This project template is used to create an ASP.NET Core Web Application, and it does not have any content by default.
  2. ASP.NET Core Web App: This Project template creates an ASP.NET Core Application using ASP.NET Core Razor Pages content.
  3. ASP.NET Core Web API: This Project template creates an ASP.NET Core Application that uses Controllers to develop Restful services. It can also be used to create ASP.NET Core MVC Views and Controllers.
  4. ASP.NET Core Web App (Model-View-Controller): This Project template creates ASP.NET Core Applications using ASP.NET Core MVC Views and Controllers. It can also be used to create restful HTTP services.
  5. Blazor Server App: This Project Template creates a Blazor server app that runs server-side inside an ASP.NET Core app and handles user interactions over a SignalR connection. This template can also be used for web apps with rich, dynamic user interfaces (UIs).
  6. Blazor WebAssembly App: This project template creates the Blazor App that runs on WebAssembly and is optionally hosted by an ASP.NET Core app. It can also be used for web apps with rich, dynamic user interfaces (UIs).
  7. Razor Class Library: This project template creates a Razor class library targeting .NET Standard.
  8. ASP.NET Core with Angular: This project template creates ASP.NET Core Applications with Angular.
  9. ASP.NET Core with React.js: This project template creates ASP.NET Core Applications with React.js.
  10. NUnit Test Project: This Project template contains NUnit tests that can run on .NET on Windows, Linux, and MacOS.

Note: In our coming articles, we will discuss how and when to use the above project templates in detail.

In the next article, I will discuss the ASP.NET Core Project File. In this article, I try to explain how to create the ASP.NET Core Web Application using Visual Studio 2022 and .NET 6. I would like to have your feedback. Please post your feedback, questions, or comments about this Creating ASP.NET Core Web Application using Visual Studio 2022 and .NET 6 article.

2 thoughts on “Creating ASP.NET Core Web Application using Visual Studio”

Leave a Reply

Your email address will not be published. Required fields are marked *