Migration from .NET Core 2.2 to .NET Core 3.1 using a real project as an example

image



This article is a logical continuation of the update of the nopCommerce project - a free open source CMS for creating online stores. Last time we talked about our experience of migrating a project from ASP.NET MVC to ASP.NET Core 2.2 . We will now look at the migration process to .NET Core 3.1. Given that the official support for .Net Core 3.1 will last until December 2022, the topic of migration is very relevant now. Therefore, if you want to get all the benefits of the updated framework, keep up with technological innovations and keep up with the gaining popularity worldwide, then it's time to start migration.



What tasks were to be solved during the transition to .NET Core 3.1



, . review .NET Core 3.0 , , , JSON. , .NET Core 2.2 . , . . , .NET Core 2.2.



.NET Core 3.1



. .NET Core 2.2 .NET Core 3.1 Microsoft. , .



Generic Host



.NET Core 2.1 Generic Host Web Host, , (DI) . .NET Core 3. Generic Host, Generic Host Builder Web Host Builder. , WPF - .



public class Program
{
    public static void Main(string[] args)
    {
        CreateHostBuilder(args).Build().Run();
    }

    public static IHostBuilder CreateHostBuilder(string[] args)
    {
        return Host.CreateDefaultBuilder(args)
            .UseServiceProviderFactory(new AutofacServiceProviderFactory())
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder
                    .UseStartup<Startup>();
            });
    }
}


WebHostBuilder, ASP.NET Core 3.1, .





global.json



.NET Core 2.0, . SDK, . SDK .NET Core 3.0 allowPrerelease rollForward. .NET Core SDK.



{
  "sdk": {
    "version": "3.1.201",
    "rollForward": "latestFeature",
    "allowPrerelease": false
  }
}


GitHub.



, , global.json . , . , SDK , , .



ASP.NET Core Module V2



.NET Core 2.2 IIS .NET Core, Kestrel ( - .NET Core) IIS Kestrel. IIS . , , IIS Kestrel . «OutOfProcess».





.NET Core 2.2 ​​ «InProcess». IIS Kestrel, IIS. , Kestrel. , .





.NET Core 3.1 , ASP.NET Core IIS. .



<PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <Copyright>Copyright (c) Nop Solutions, Ltd</Copyright>
    <Company>Nop Solutions, Ltd</Company>
    <Authors>Nop Solutions, Ltd</Authors>
    <Version>4.4.0.0</Version>
    <Description>Nop.Web is also an MVC web application project, a presentation layer for public store and admin area.</Description>
    <PackageLicenseUrl>https://www.nopcommerce.com/license</PackageLicenseUrl>
    <PackageProjectUrl>https://www.nopcommerce.com/</PackageProjectUrl>
    <RepositoryUrl>https://github.com/nopSolutions/nopCommerce</RepositoryUrl>
    <RepositoryType>Git</RepositoryType>
    <!--Set this parameter to true to get the dlls copied from the NuGet cache to the output of your project-->
    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
    <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
    <!--When true, compiles and emits the Razor assembly as part of publishing the project-->
    <RazorCompileOnPublish>false</RazorCompileOnPublish>
  </PropertyGroup>


, Linux -.

, , , .



Endpoint Routing



.NET Core 2.1 Middleware ( ASP.NET Core MVC) HTTP-. , , , , , MVC . .NET Core 2.2 , (Endpoints), .

.NET Core 3.1 Endpoint Routing , . middleware:



  • EndpointRoutingMiddleware — , URL ,
  • EndpointMiddleware




, , , middleware , .



/// <summary>
/// Configure Endpoints routing
/// </summary>
/// <param name="application">Builder for configuring an application's request pipeline</param>
public static void UseNopEndpoints(this IApplicationBuilder application)
{
    //Add the EndpointRoutingMiddleware
    application.UseRouting();

    //Execute the endpoint selected by the routing middleware
    application.UseEndpoints(endpoints =>
    {
        //register all routes
        EngineContext.Current.Resolve<IRoutePublisher>().RegisterRoutes(endpoints);
    });
}


, .

GitHub.



# 8.0



.NET Core C# 8.0. . , , “ ”.





.





nopCommerce, , .. eCommerce .



Windows 10 (10.0.19041.388), IIS 10 (10.0.19041.1) - - Kestrel . Apache JMeter, . , 50 , — 516 , — 50 , — 80 1 5 . MS SQL Server 2017 (14.0.2014.14).



JMeter , . .



20% ( )





(Average) 13.7% ( )





, .. (throughput) 12.7% ( )





, , , . , . ASP.NET Core .





— 1,5 . , 2 . .



, AspNetCoreModule, .NET Core 2.2. .





, .







.NET Core - . , , . .NET Core , . 13%. , , , . , , performance refactoring : .



, , , .NET Core , , .NET Core 3.1.0 ( 3.5.1) — security patch.



, .NET Core 3.1 LTS 2.1, , . LTS .NET Core. .NET 5, .NET Core 3.1 — .



In the future, we plan to further update our nopCommerce application, adding more and more new features that the .NET Core platform provides. One of them is the move to use System.Text.Json instead of Newtonsoft.Json . This is a more performant, safer, and more standardized approach to handling JSON objects. We also plan to implement and use as many features as possible that C # 8.0 provides.



You can find out more about our project on nopcommerce.com or by visiting our repository on GitHub .




All Articles