Subscribe to Youtube channel

Step by step migration of ASP.NET Core 2.2 to 3.1

In order to upgrade/migrate core version to 3.1 following steps to be perform.

  • Download and install Visual Studio 2019 version 16.4 or higher.
  • Download and install .NET Core 3.1
  • Upgrade the projects of solution to .NET Core 3.1 , because ASP.NET Core 3.1 requires it.
  • Update existing Nuget packages to a version compatible with ASP.NET Core 3.1 in each project
  • Use IHost interface from a IHostBuilder instead of building and running a IWebHost from a IWebHostBuilder in Program.cs
  public static IHostBuilder CreateWebHostBuilder(string[] args) =>  
           .ConfigureWebHostDefaults(webBuilder =>  
  • Change AddMvc method has been replaced by AddControllers in Startup.cs of each projects.
  • In Startup.cs, UseMvc method to be replaced by UseRouting method and UseEndpoints method. Note that these two methods must not be nested if you are using Authentication and Authorization. UseRouting method must be set before UseAuthentication and UseAuthorization methods. UseEndpoints method has to be set at the end.
  • IHostingEnvironment to be replaced by IHostEnvironment in all projects 
  • Replace UseSignalR with UseEndpoint method in Startup.cs
 public class Startup  
     public Startup(IConfiguration configuration)  
       Log.Logger = new LoggerConfiguration().ReadFrom.Configuration(configuration).CreateLogger();  
       Configuration = configuration;  
     public IConfiguration Configuration { get; }  
     public void ConfigureServices(IServiceCollection services)  
       services.AddControllers().AddNewtonsoftJson(options =>   
         options.SerializerSettings.Formatting = Newtonsoft.Json.Formatting.Indented;  
         options.SerializerSettings.ContractResolver = new DefaultContractResolver();  
       services.AddHttpClient<IDataClient, DataClient>(client =>  
         client.BaseAddress = new Uri("http://localhost:4444/api/");  
     public void Configure(IApplicationBuilder app, IHostEnvironment env)  
       if (env.IsDevelopment())  
         app.UseEndpoints(endpoints =>  
       // Needs to be added after UseRouting() in 3.1  
       // app.UseAuthorization();   
       app.UseEndpoints(endpoints =>  


Popular posts from this blog

Implement Logging in CSV file using Nlog in .net core MVC application- part 2

Implement Nlog in .Net core MVC application part 1

Devexpress Datebox date formatting in angular 6 with example

Disable backspace key using Jquery

Angular User Session Timeout example step by step

Restore the lost focus of Auto post back controls in update Panel control

How to Import CSV File and bind csv file data to gridview in using c#

Remove Owin from MVC 5 Application and use custom forms authentication

Clone a generic list in C# using extension method