Migrate .NET Core v2 MVC app to v3
For migrating your .NET Core v2 MVC app to v3 use the following steps
- Change the .NET Core version of your web app to .NET Core v3.1 or higher
- Change your Startup.cs in your web root
- Remove the following line
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); - Add the following line to the ConfigureServices method
services.AddControllersWithViews(); - Change the signature of method from
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
to
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) - If you use a env.IsDevelopment() statement add the following in the top of your Startup.cs
using Microsoft.Extensions.Hosting; - Add the following lines to the bottom of your Configure method
app.UseRouting();
app.UseCors(); - Only add the following lines if you use authentication / authorization
app.UseAuthentication();
app.UseAuthorization(); - Convert your web routes from
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
To
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
}); - Remove the Microsoft.AspNetCore.Razor.Design nuget package
Comments