In this short article, we are going to create a new project, an ASP .NET Core API project. We are going to use the preview version of Visual Studio 2022 (version 17.4). Let’s check out how the new project template looks like.
Visual Studio Preview v17.4
This version of Visual Studio has some exciting new features. Some special mentions in the announcement blog are – Git Tooling, Code Search, Selection Match Highlighting, etc.
Installing .NET 7 RC1
For this demo, In addition to latest preview of Visual Studio 2022, we will also need to install the release candidate of .NET 7.
Visual Studio – New Project Wizard
Now, let’s start the new Visual Studio. The wizard for opening an existing project or creating new project is automatically shown. Select the
ASP .NET Core API project template. Then on the next screen in wizard, enter the project name and the path where the project file should be saved.
The next screen in the new project creation wizard will show some new options.
.NET 7in the target framework dropdown.
- There is option to select
- Then there is one checkbox to configure for
- And another checkbox for enabling docker. There is also option to select OS for docker container.
- Then there are also options to enable swagger page in the project.
- Another option is to select enable controllers or minimal APIs.
As far as I remember, all these options are also present in Visual Studio 2022 v17.3. There is no big change as such in the project creation wizard. Now, click on Create button to create the project.
.NET 7 – API Project Template
Now, that we have created the project, let’s have a look at the solution explorer. The snapshot is given below.
The project template looks to be almost same as in .NET 6. There is a weather forecast controller. There is a model which is used as output type for the weather forecast get operation.
There is no Startup class since .NET 6
There is no
Startup.cs file in this template. There are only few lines, which are part of
Main method. The method contains code to register services and middleware in the request processing pipeline.
In .NET 5 project template, there was a separate Startup class and it has two different methods to configure services and configure request processing pipeline.
In .NET 6, this Startup type was removed. I am not sure why Startup file was removed from the template. I personally liked to keep the contents outside of Main method, in a type / method which is dedicated to that specific purpose. I am sure many of us will agree to this thought.
I think, if we need, we can still add the Startup file and move the code to configure services and middleware to that file as it used to be in earlier versions of .NET.
When I started writing this article, I was hoping there would be some surprizes and may be
startup.cs file may have made comeback to the project template. But that was not the case.
We have seen that there are no bigger surprizes as such when it comes to project creation wizard of ASP .NET Core API project template.
Did you get chance to play with Visual Studio preview or .NET 7 yet ? How is your experience ?
Let me know your thoughts.