--- title: Migrate from ASP.NET Core 6.0 to 7.0 author: rick-anderson description: Learn how to migrate an ASP.NET Core 6 project to ASP.NET Core 7.0. ms.author: riande ms.date: 10/14/2022 uid: migration/60-to-70 --- # Migrate from ASP.NET Core 6.0 to 7.0 This article explains how to update an existing ASP.NET Core 6.0 project to ASP.NET Core 7.0. ## Prerequisites # [Visual Studio](#tab/visual-studio) [!INCLUDE[](~/includes/net-prereqs-vs-7.0.md)] # [Visual Studio Code](#tab/visual-studio-code) [!INCLUDE[](~/includes/net-prereqs-vsc-7.0.md)] # [Visual Studio for Mac](#tab/visual-studio-mac) [!INCLUDE[](~/includes/net-prereqs-mac-7.0.md)] --- ## Update .NET Core SDK version in global.json If you rely on a [global.json](/dotnet/core/tools/global-json) file to target a specific .NET Core SDK version, update the `version` property to the .NET 7.0 SDK version that's installed. For example: ```diff { "sdk": { - "version": "6.0.200" + "version": "7.0.100" } } ``` ## Update the target framework Update the project file's [Target Framework Moniker (TFM)](/dotnet/standard/frameworks) to `net7.0`: ```diff - net6.0 + net7.0 ``` ## Update package references In the project file, update each [Microsoft.AspNetCore.*](https://www.nuget.org/packages?q=Microsoft.AspNetCore.*), [Microsoft.EntityFrameworkCore.*](https://www.nuget.org/packages?q=Microsoft.EntityFrameworkCore.*), [Microsoft.Extensions.*](https://www.nuget.org/packages?q=Microsoft.Extensions.*), and [System.Net.Http.Json](https://www.nuget.org/packages/System.Net.Http.Json) package reference's `Version` attribute to 7.0.0 or later. For example: ```diff - - - - + + + + ``` ## Blazor ### Adopt .NET 7 features After following the guidance earlier in this article to update an app to 7.0, adopt specific features by following the links in . To adopt all of the [new 7.0 features for Blazor apps](xref:aspnetcore-7#blazor), we recommend the following process: * Create a new 7.0 Blazor project from one of the Blazor project templates. For more information, see . * Move the app's components and code to the 7.0 app making modifications to adopt the new 7.0 features. ### Simplify component parameter binding In prior Blazor releases, binding across multiple components required binding to properties with `get`/`set` accessors. In .NET 6 and earlier: ```razor @code { ... private string BoundValue { get => ChildMessage ?? string.Empty; set => ChildMessageChanged.InvokeAsync(value); } } ``` In .NET 7, you can use the new `@bind:get` and `@bind:set` modifiers to support two-way data binding and simplify the binding syntax: ```razor ``` For more information, see the following content in the *Data binding* article: * [Introduction](xref:blazor/components/data-binding?view=aspnetcore-7.0) * [Bind across more than two components](xref:blazor/components/data-binding?view=aspnetcore-7.0#bind-across-more-than-two-components) ### Migrate unmarshalled JavaScript interop Unmarshalled interop using the interface is obsolete and should be replaced with JavaScript `[JSImport]`/`[JSExport]` interop. For more information, see . ### Blazor WebAssembly authentication uses history state for redirects The support for authentication in Blazor WebAssembly apps changed to rely on [navigation history state](xref:blazor/fundamentals/routing?view=aspnetcore-7.0#navigation-history-state) instead of query strings in the URL. As a result, passing the return URL through the query string fails to redirect back to the original page after a successful login in .NET 7. The following example demonstrates **the prior redirection approach for apps that target .NET 6 or earlier**, which is based on a redirect URL (`?returnUrl=`) with : ```razor @inject NavigationManager Navigation @using Microsoft.AspNetCore.Components.WebAssembly.Authentication @code { protected override void OnInitialized() { Navigation.NavigateTo( $"authentication/login?returnUrl={Uri.EscapeDataString(Navigation.Uri)}"); } } ``` The following example demonstrates **the new redirection approach for apps that target .NET 7 or later**, which is based on [navigation history state](xref:blazor/fundamentals/routing?view=aspnetcore-7.0#navigation-history-state) with : ```razor @inject NavigationManager Navigation @using Microsoft.AspNetCore.Components.WebAssembly.Authentication @using Microsoft.Extensions.Options @inject IOptionsSnapshot> Options @code { protected override void OnInitialized() { Navigation.NavigateToLogin(Options.Get( Microsoft.Extensions.Options.Options.DefaultName) .AuthenticationPaths.LogInPath); } } ``` As part of this change, is obsolete in .NET 7 or later and replaced with . The following example demonstrates **the prior approach** in `Shared/LoginDisplay.razor` of an app generated from the Blazor WebAssembly project template: ```razor @inject SignOutSessionStateManager SignOutManager ... @code{ private async Task BeginLogout(MouseEventArgs args) { await SignOutManager.SetSignOutState(); Navigation.NavigateTo("authentication/logout"); } } ``` The following example demonstrates **the new approach** that calls . The injection (`@inject`) of the is removed from the component's directives at the top of the file, and the `BeginLogOut` method is updated to the following code: ```razor @code{ public void BeginLogOut() { Navigation.NavigateToLogout("authentication/logout"); } } ``` The service registration is removed in `Program.cs`: ```diff - builder.Services.AddScoped(); ``` For more information, see the following resources: * [[Breaking change]: Updates to Authentication in webassembly applications](https://github.com/aspnet/Announcements/issues/497) * * * ### .NET WebAssembly build tools for .NET 6 projects You can now use the .NET WebAssembly build tools with a .NET 6 project when working with the .NET 7 SDK. The new `wasm-tools-net6` workload includes the .NET WebAssembly build tools for .NET 6 projects so that they can be used with the .NET 7 SDK. The existing `wasm-tools` workload installs the .NET WebAssembly build tools for .NET 7 projects. However, the .NET 7 version of the .NET WebAssembly build tools are incompatible with existing projects built with .NET 6. Projects using the .NET WebAssembly build tools that need to support both .NET 6 and .NET 7 must use multi-targeting. ## Update Docker images For apps using Docker, update your *Dockerfile* `FROM` statements and scripts. Use a base image that includes the ASP.NET Core 7.0 runtime. Consider the following `docker pull` command difference between ASP.NET Core 6.0 and 7.0: ```diff - docker pull mcr.microsoft.com/dotnet/aspnet:6.0 + docker pull mcr.microsoft.com/dotnet/aspnet:7.0 ``` ## Review breaking changes For breaking changes from .NET Core 6.0 to .NET 7.0, see [Breaking changes in .NET 7](/dotnet/core/compatibility/7.0). ASP.NET Core and Entity Framework Core are included in the list.