--- title: Migrate from ASP.NET Core 5.0 to 6.0 author: rick-anderson description: Learn how to migrate an ASP.NET Core 5.0 project to ASP.NET Core 6.0. ms.author: scaddie ms.date: 03/15/2021 no-loc: [Home, Privacy, Kestrel, appsettings.json, "ASP.NET Core Identity", cookie, Cookie, Blazor, "Blazor Server", "Blazor WebAssembly", "Identity", "Let's Encrypt", Razor, SignalR] uid: migration/50-to-60 --- # Migrate from ASP.NET Core 5.0 to 6.0 This article explains how to update an existing ASP.NET Core 5.0 project to ASP.NET Core 6.0. ## Prerequisites # [Visual Studio](#tab/visual-studio) [!INCLUDE[](~/includes/net-prereqs-vs-6.0.md)] # [Visual Studio Code](#tab/visual-studio-code) [!INCLUDE[](~/includes/net-prereqs-vsc-6.0.md)] # [Visual Studio for Mac](#tab/visual-studio-mac) [!INCLUDE[](~/includes/net-prereqs-mac-6.0.md)] --- ## Update .NET SDK version in global.json If you rely upon a [global.json](/dotnet/core/tools/global-json) file to target a specific .NET SDK version, update the `version` property to the .NET 6.0 SDK version that's installed. For example: ```diff { "sdk": { - "version": "5.0.100" + "version": "6.0.100-preview.2.21155.3" } } ``` ## Update the target framework Update the project file's [Target Framework Moniker (TFM)](/dotnet/standard/frameworks) to `net6.0`: ```diff - net5.0 + net6.0 ``` ## Update package references In the project file, update each [Microsoft.AspNetCore.*](https://www.nuget.org/packages?q=Microsoft.AspNetCore.*) and [Microsoft.Extensions.*](https://www.nuget.org/packages?q=Microsoft.Extensions.*) package reference's `Version` attribute to 6.0.0 or later. For example: ```diff - - + + ``` ## Update Docker images For apps using Docker, update your *Dockerfile* `FROM` statements and scripts. Use a base image that includes the ASP.NET Core 6.0 runtime. Consider the following `docker pull` command difference between ASP.NET Core 5.0 and 6.0: ```diff - docker pull mcr.microsoft.com/dotnet/aspnet:5.0 + docker pull mcr.microsoft.com/dotnet/aspnet:6.0 ``` ## Changes to the ASP.NET Core Razor SDK The Razor compiler now leverages the new [source generators feature](https://devblogs.microsoft.com/dotnet/introducing-c-source-generators/) to generate compiled C# files from the Razor views and pages in a project. In previous versions: * The compilation relied on the `RazorGenerate` and `RazorCompile` targets to produce the generated code. These targets are no longer valid. In .NET 6, both code generation and compilation are supported by a single call to the compiler. `RazorComponentGenerateDependsOn` is still supported to specify dependencies that are required before the build runs. * A separate Razor assembly, `AppName.Views.dll`, was generated that contained the compiled view types in an application. This behavior has been deprecated and a single assembly `AppName.dll` is produced that contains both the app types and the generated views. * The app types in `AppName.Views.dll` were public. In .NET 6, the app types are in `AppName.dll` but are `internal sealed`. Apps doing type discover on `AppName.Views.dll` won't be able to do type discover on `AppName.dll`. The following shows the API change: ```diff - public class Views_Home_Index : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage + internal sealed class Views_Home_Index : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage ``` Make the following changes: * The following properties are no longer applicable with the single-step compilation model. * `RazorTargetAssemblyAttribute` * `RazorTargetName` * `EnableDefaultRazorTargetAssemblyInfoAttributes` * `UseRazorBuildServer` * `GenerateRazorTargetAssemblyInfo` * `GenerateMvcApplicationPartsAssemblyAttributes` For more information, see [Razor compiler no longer produces a Views assembly](https://github.com/aspnet/Announcements/issues/459). ## Project templates use Duende Identity Server Project templates now use [Duende Identity Server](https://docs.duendesoftware.com). For migration guidance, see [IdentityServer4 v4.1 to Duende IdentityServer v5](https://docs.duendesoftware.com/identityserver/v5/upgrades/is4_v4_to_dis_v5/). > [!IMPORTANT] > Duende Identity Server is an open source product with a reciprocal license agreement. If you plan to use Duende Identity Server in production, you might be required to obtain a commercial licence from [Duende Software](https://duendesoftware.com/) and pay a license fee. For more information, see [Duende Software: Licenses](https://aka.ms/identityserverlicense). > > To learn how to use [Microsoft Azure Active Directory](https://azure.microsoft.com/services/active-directory/) for ASP.NET Core Identity, see [Identity (dotnet/aspnetcore GitHub repository)](https://aka.ms/aspnetidentityserver). Add a `DbSet` property named `Keys` to every `IdentityDbContext` to satisfy a new requirement from the updated version of `IPersistedGrantDbContext`. The keys are required as part of the contract with Duende Identity Server's stores. ```csharp public DbSet Keys { get; set; } ``` > [!NOTE] > Existing migrations must be recreated for Duende Identity Server. ## Review breaking changes For breaking changes from .NET 5.0 to .NET 6.0, see [Breaking changes for migration from version 5.0 to 6.0](/dotnet/core/compatibility/6.0). ASP.NET Core and Entity Framework Core are also included in the list.