Subscribe to Youtube channel

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

In order to upgrade/migrate asp.net 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  https://dotnet.microsoft.com/download/dotnet-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) =>  
           Host.CreateDefaultBuilder(args)  
           .ConfigureWebHostDefaults(webBuilder =>  
           {  
             webBuilder.UseKestrel()  
                  .UseSerilog()  
                  .UseStartup<Startup>();  
           })  
  • 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();  
       }).SetCompatibilityVersion(CompatibilityVersion.Version_3_0)  
       .AddFluentValidation();  
        services.AddSignalR();  
       services.AddHttpClient<IDataClient, DataClient>(client =>  
       {  
         client.BaseAddress = new Uri("http://localhost:4444/api/");  
       })  
       .AddPolicyHandlers(policyConfig);  
       services.AddApplicationInsightsTelemetry();  
     }  
     public void Configure(IApplicationBuilder app, IHostEnvironment env)  
     {  
       if (env.IsDevelopment())  
       {  
         app.UseDeveloperExceptionPage();  
       }  
       app.UseRouting();  
         app.UseEndpoints(endpoints =>  
                  {     
                   endpoints.MapHub<MyHub>("/myHub");  
                 });  
       // Needs to be added after UseRouting() in 3.1  
       // app.UseAuthorization();   
       app.UseEndpoints(endpoints =>  
       {  
         endpoints.MapDefaultControllerRoute();  
       });  
     }  
   }  

Comments

  1. Great Work. I always follow your valuable contents. Thanks for sharing this kind of knowledge. It is very helpful and very informative and I really learned a lot from it. Further More Information About AUTOCAD Training Institute in Delhi So Contact Here-+91-9311002620 Or Visit Website- https://www.htsindia.com/AutoCAD-training-courses

    ReplyDelete

Post a Comment

Popular posts from this blog

Root your Gingerbread 2.3.4 android Mobile Phone

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

Disable backspace key using Jquery

Devexpress Datebox date formatting in angular 6 with example

Implement Nlog in .Net core MVC application part 1

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

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

Source Code Beautifier And Format Source Code For Blogger and Websites

Clone a generic list in C# using extension method