Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Creating First ASP.

NET Core Web Application using Visual Studio 2022


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 then click on the Next button
as shown in the below image.

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.

Trainer: Pranaya Kumar Rout Website: https://dotnettutorials.net/


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 that you can see here is, we don’t have the
Startup class anymore which we found in the earlier version of ASP.NET Core Framework.

Run ASP.NET Core Application:

Trainer: Pranaya Kumar Rout Website: https://dotnettutorials.net/


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.

Trainer: Pranaya Kumar Rout Website: https://dotnettutorials.net/


Let us understand what are all these project templates and their use.
1. 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.
2. ASP.NET Core Web App: This Project template is used for creating ASP.NET Core
Application using ASP.NET Core Razor Pages content.
3. ASP.NET Core Web API: This Project template is used for creating ASP.NET Core
Application that uses Controllers for developing Restful services. This Project template can also
be used for creating ASP.NET Core MVC Views and Controllers.
4. ASP.NET Core Web App (Model-View-Controller): This Project template is used for
creating ASP.NET Core Web Applications using ASP.NET Core MVC Views and Controllers.
This Project template can also be used for creating Restful HTTP Services.
5. 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).
6. 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).
7. Razor Class Library: This Project template is used for creating a Razor class library that
targets .NET Standard.
8. ASP.NET Core with Angular: This Project template is used for creating ASP.NET Core
Applications with Angular.
9. ASP.NET Core with React.js: This Project template is used for creating 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 sessions, we will discuss how and when to use some of the above project templates
in detail.

Trainer: Pranaya Kumar Rout Website: https://dotnettutorials.net/

You might also like