Migrating from ASP.NET Core 5.0 MVC app to 6.0
This post is about how to update an existing ASP.NET Core 5.0 MVC project to ASP.NET Core 6.0. I am sharing my experience while upgrading one of .NET 5.0 project to the .NET 6.0. First we need to upgrade
TargetFramework element in the
csproj file from
net6.0. We can enable other .NET 6.0 framework features as well, like
Next we need to update the versions of
Microsoft.AspNetCore nuget packages to the latest version of .NET 6.0.
Next we can combine both
Startup.cs. In the
Program.cs remove the
static void Main(), class declaration and namespace declaration etc. Here is the .NET 6.0 -
We can access the configuration from
builder.Configuration property, like this.
Then we can delete the
Startup.cs file. And if we enabled the
Nullable attribute, we can put the
? operator after
RequestId in the
ErrorViewModel. Another important aspect related to Nullable feature is by default ASP.NET Core will consider every field as required if there is no nullable operator. It can be a breaking change.
I am using GitHub actions for the deployment, so I had to upgrade the
Set up .NET Core step to use .NET 6.0 instead of .NET 5.0. Here is the updated GitHub Actions file.
I am deploying it to Azure App Service, so I had to upgrade the .NET Version to .NET 6 (LTS) version - from the General Settings, Configuration menu. Here is the screenshot the app service configuration.
It is a simple project, so I don’t have to do much changes. Since I enabled the
Nullable attribute I had to modify the code little bit. Here the official migration Guide - Migrate from ASP.NET Core 5.0 to 6.0
Happy Programming :)