I. Introduction

.NET Core 3.0 will be officially released at the .NET Conf conference. As of today, 9 previews have been released. There are also many changes. Due to the lack of continuous attention, today’s dynamic open
WebApi project has been

migrated to .NET Core 3.0. I spent a lot of time on the pit and shared with you the pits I encountered during the migration. The migrated version is the latest Release version of .NET Core 2.2 to .NET Core 3.0 Preview 9.

ASP.NET Core project migration

Official migration documentation: Migrating
from ASP.NET Core 2.2 to 3.0

, this official document is more detailed, but there are some things that are not written.

1. Change the frame version

Change the TargetFramework version to netcoreapp3.0

ASP.NET_Core_3.0_Migration_Guide_0.png

2. Remove the Nuget package

Remove the Nuget package below

ASP.NET_Core_3.0_Migration_Guide_1.png

Update the remaining Nuget packages to support the .NET Core 3.0 version

3.Program changes

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

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

ASP.NET_Core_3.0_Migration_Guide_2.png

4.Startup changes

ConfigureServices method:

  1. services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);services.AddControllers()Change to (WebApi) / services.AddControllersWithViews();(MVC)

ASP.NET_Core_3.0_Migration_Guide_3.png

Configure method:

  1. In this method, the host environment information interface type is obtained, and is IHostingEnvironmentchanged toIWebHostEnvironment

    ASP.NET_Core_3.0_Migration_Guide_4.png

  2. app.UseMVc Change to:

WebApi:

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

MVC:

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
            });

About Json components

ASP.NET Core 3.0 is removed by default Newtonsoft.Json, using Microsoft’s own implementation System.Text.Json. If you want to change to Newtonsoft.Json, then there are two steps:

1. Install the Nuget package:

Install-Package Microsoft.AspNetCore.Mvc.NewtonsoftJson

2. Registration

services.AddControllers().AddNewtonsoftJson();

Class Library Net Standard 2.0 project migration

Because of ASP.NET Core 3.0 changes to the meta-package mechanism,
Microsoft.AspNetCore.All

or
Microsoft.AspNetCore.App

version 3.0 cannot be installed via nuget , and most of the Nuget packages they contain cannot be installed via nuget (no 3.0 counterparts) version of). If you also refer to the 2.2 version of the nuget package, you may get an error when you run it. The meta package is included in the .NET Core SDK, which means that if our class library project relies on AspNetCore related components, then we will not be able to continue to set the project target framework to .NET Standard, which can only be set to .NET Core. 3.0, because ASP.NET Core 3.0 only runs on .NET Core .

Reason for the change of the meta-package mechanism:
https://github.com/aspnet/AspNetCore/issues/3608

ASP.NET_Core_3.0_Migration_Guide_5.png

1. Change the frame version

2. Update the Nuget package

Remove Microsoft.AspNetCore.* does not have a version of .NET Core 3.0, for example:

ASP.NET_Core_3.0_Migration_Guide_7.png

Add a FrameworkReference (not a PackageReference) reference:

End

Off-topic: ASP.NET Core will run in both the .NET Framework and .NET Core until 2.2, but starting with ASP.NET Core 3.0, it will only support .NET Core.

Related information:
A first look at changes coming in ASP.NET Core 3.0

The changes mentioned above, Microsoft official has explained the reason, in fact, in order to become better and change, to make up for the previous shortcomings, but for the Core used for so long is a bit toss, but still acceptable, for better .NET Core.

Orignal link:https://www.cnblogs.com/stulzq/p/11497624.html