Back to: ASP.NET Core Tutorials For Beginners and Professionals
Creating ASP.NET Core Web Application using .NET 6
In this article, I am going to discuss How to Create the ASP.NET Core Web Application using Visual Studio 2022 and .NET 6. Please, read our previous article, where we discussed the Differences Between .NET Core vs. .NET Framework.
Creating the First ASP.NET Core Web Application using Visual Studio 2022 and .NET 6
To create a new ASP.NET Core Application using .NET 6, open Visual Studio 2022, and then click on the Create a new project box as shown in the below image.
Once you click on the Create a new project box, it will open the “Create a new project” window. 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.
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.
Once you click on the Next button, it will open the Additional Information window. Here, you need to select .NET 6.0 as the Framework; you also need to check the Configure for HTTPS and Do not use top-level statements check boxes, and finally, click on the Create button as shown in the below image.
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.
Run ASP.NET Core Application:
To run this ASP.NET Core Web Application, click on IIS Express or press F5 (with Debug) or Ctrl + F5 (without Debug). This will open the browser and display the following output.
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.
Now, open the Program.cs class file and then change the “Hello World!” string to something else as shown in the below code and 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 below image, while creating ASP.NET Core Application, we have different types of project templates for creating ASP.NET Core Web applications.
Let us understand what all these project templates and their use are.
- ASP.NET Core Empty: This Project template is used for creating ASP.NET Core Web Application, and this project template does not have any content in it by default.
- ASP.NET Core Web App: This Project template is used for creating ASP.NET Core Application using ASP.NET Core Razor Pages content.
- ASP.NET Core Web API: This Project template is used to create ASP.NET Core Application that uses Controllers to develop Restful services. This Project template can also be used for creating ASP.NET Core MVC Views and Controllers.
- ASP.NET Core Web App (Model-View-Controller): This Project template is used for creating ASP.NET Core Applications using ASP.NET Core MVC Views and Controllers. This Project template can also be used for creating Restful HTTP Services.
- Blazor Server App: This Project Template is used for creating 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).
- Blazor WebAssembly App: This Project template is used for creating Blazor App that runs on WebAssembly and is optionally hosted by an ASP.NET Core app. This template can also be used for web apps with rich, dynamic user interfaces (UIs).
- Razor Class Library: This Project template is used for creating a Razor class library that targets .NET Standard.
- ASP.NET Core with Angular: This Project template is used for creating ASP.NET Core Applications with Angular.
- ASP.NET Core with React.js: This Project template is used for creating ASP.NET Core Applications with React.js.
- 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 am going to discuss the ASP.NET Core Project File. Here, 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, question, or comments about this Creating ASP.NET Core Web Application using Visual Studio 2022 and .NET 6 article.
still learning
Very nice tutorial