Migration de .NET Core 2.2 vers .NET Core 3.1 en utilisant un vrai projet comme exemple

image



Cet article est une suite logique de la mise à jour du projet nopCommerce - un CMS open source gratuit pour la création de boutiques en ligne. La dernière fois, nous avons parlé de notre expérience de migration d'un projet d'ASP.NET MVC vers ASP.NET Core 2.2 . Nous allons maintenant examiner le processus de migration vers .NET Core 3.1. Étant donné que le support officiel de .Net Core 3.1 durera jusqu'en décembre 2022, le sujet de la migration est désormais très pertinent. Par conséquent, si vous souhaitez profiter de tous les avantages du cadre mis à jour, suivre les innovations technologiques et suivre la popularité croissante dans le monde, il est temps de commencer la migration.



Quelles tâches ont dû être résolues lors de la transition vers .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 — .



À l'avenir, nous prévoyons de mettre à jour davantage notre application nopCommerce, en ajoutant de plus en plus de nouvelles fonctionnalités fournies par la plate-forme .NET Core. L'un d'eux est la décision d'utiliser System.Text.Json au lieu de Newtonsoft.Json . Il s'agit d'une approche plus performante, plus sûre et plus standardisée de la gestion des objets JSON. Nous prévoyons également d'implémenter et d'utiliser autant de fonctionnalités que possible que C # 8.0 fournit.



Vous pouvez en savoir plus sur notre projet sur nopcommerce.com ou en visitant notre référentiel sur GitHub .




All Articles