logo

,

Startup.cs Missing in .Net 6 and Above

Let’s discuss in this article the changes in .Net 6 with the missing Startup.cs file. So let’s get started.

We .Net core developers are very familiar with the Startup.cs file, the ConfigureServices & the Configure methods in the Startup.cs file. Now, Let me tell you that you will not find the Startup.cs file from .Net 6 onwards. So, what happened to our so important Startup.cs file in .Net 6?

For this, I will be creating two Asp.net core MVC web applications. One in .Net 5 and the other in .Net 6. We will compare these two projects side by side and understand what has happened with the Startup.cs file.

Comparison

As you can see from the above screenshot of both the .Net 5 and .Net 6 projects, the Startup.cs file is missing in the .Net 6 project. Now, what happened here in .Net 6 is the Startup.cs file has been moved into the Program.cs file. Or we can say that the contents of the Startup.cs of .Net 5 have been moved to Program.cs in .Net 6.

.Net 5 Startup.cs vs .Net 6 Program.cs

Files Comparison

  1. In .Net 6 we create the builder in the Program.cs file and under the builder we add the service to the container. So whatever we have in the ConfigureServices method in the .Net 5 Startup.cs those entries go and get added under the builder services in .Net 6 Program.cs.
  2. In .Net 5 we had the Configure method in the Startup.cs where we add items to the request pipeline. Now with .Net 6 whatever we have in the Configure method in .Net 5 Startup.cs. Those entries are also in the same Program.cs file in .Net 6, below the “Configure the HTTP request pipeline” comment.

This is a very small change but I wanted to make sure that my fellow programmers are aware of this change.

Don’t forget to check out Learn Mobile App Development with .NET MAUI

Don’t forget to check out Generate QR Code in Asp.net Core with 4 Simple Steps

 

9 Responses

  1. Thank you for this.
    While simple, the change is surprising.
    I was looking for Startup.cs when I created a new Web API project.

  2. I know this if off topic but I’m looking into starting my own weblog and was curious what all is needed
    to get setup? I’m assuming having a blog like yours would cost a pretty penny?
    I’m not very web smart so I’m not 100% certain. Any tips
    or advice would be greatly appreciated. Appreciate it

Comments are closed.

Share on facebook
Share on twitter
Share on linkedin

Related articles