Understanding the Program.cs File in Newer Versions of ASP.NET

Learn to understand the backend entry points of the project in the latest version of .NET.

We'll cover the following

In this lesson, we will see how we can migrate the ASP.NET application to the latest version. We are using .NET 7. In newer versions, the Startup.cs and Program.cs files have been merged into a single file called Program.cs with the following changes:

  • ConfigureServices is replaced with WebApplication.Services.

  • builder.Build() returns a configured WebApplication to the variable app. Configure is replaced with configure calls to the same services using app.

The Program.cs file

The new Program.cs file is given as follows in which WebApplication.CreateBuilder method creates a new instance of the WebApplicationBuilder class, which is used to configure the application’s services and request/response pipeline.

The new file will come here:

Get hands-on with 1200+ tech skills courses.