Skip to content

Instantly share code, notes, and snippets.

@dodbrian
Last active July 24, 2020 16:17
Show Gist options
  • Save dodbrian/45a50559c06262185de8fec867f42239 to your computer and use it in GitHub Desktop.
Save dodbrian/45a50559c06262185de8fec867f42239 to your computer and use it in GitHub Desktop.
Migration from .NET Core 2.2 to 3.1

Migration from .NET Core 2.2 to 3.1

Update *.csproj files

Change target framework:

<TargetFramework>netcoreapp3.1</TargetFramework>

or for libraries:

<TargetFramework>netstandard2.1</TargetFramework>

Get rid of All or App package:

<PackageReference Include="Microsoft.AspNetCore.All" />

ASP.NET Core

Migrate from Newtonsoft.Json

SerializerSettings in AddJsonOptions are no longer available.

Controllers

  • CreatedAtRoute now throws an error InvalidOperationException: "No route matches the supplied values." if supplied params doesn't match the endpoint method signature.
  • An attempt to call an endpoint where the specified method is missing will now return a MethodNotAllowed HTTP status code instead of NotFound in .NET Core 2.x.

Http

Internal namespace is removed:

using Microsoft.AspNetCore.Http.Internal;

Method EnableRewind is replaced with EnableBuffering.

HttpContext

The propery HttpContext.Authentication has been removed which breaks compatibility with older versions of IdentityServer4.

Entity Framework changes

IMutableEntityType no longer contains definition for Relational. Should be replaced with new API. See discussion here.

Some RelationalEventId members are removed or changed:

  • QueryPossibleExceptionWithAggregateOperator replaced with QueryPossibleExceptionWithAggregateOperatorWarning.
  • QueryClientEvaluationWarning is no longer supported.

Migrations

Migrations are no longer available by default and must be installed explicitly. For the CLI the following command should be issued:

dotnet tool install --global dotnet-ef

When using Visual Studio's Packet Management Console (PMC) the following references must be added to a project contaning migrations:

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.5">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
    </PackageReference>
  </ItemGroup>

and the startup project must contain:

    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.5">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>

Without this changes such commands as Add-Migration are not available in PMC.

AutoMapper

IdentityServer4 depends on AutoMapper which requires to upgrade it to version 9.0.0. This version has some breaking changes and in particular doesn't support automatic mappings by default.

Related resources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment