Migrate from ASP.NET Core in .NET 8 to ASP.NET Core in .NET 9

This article explains how to update an ASP.NET Core in .NET 8 to ASP.NET Core in .NET 9.

Prerequisites

Update the .NET SDK version in global.json

If you rely on a global.json file to target a specific .NET Core SDK version, update the version property to the .NET 9.0 SDK version that's installed. For example:

{
  "sdk": {
-    "version": "8.0.100"
+    "version": "9.0.100"
  }
}

Update the target framework

Update the project file's Target Framework Moniker (TFM) to net9.0:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
-    <TargetFramework>net8.0</TargetFramework>
+    <TargetFramework>net9.0</TargetFramework>
  </PropertyGroup>

</Project>

Update package references

In the project file, update each Microsoft.AspNetCore.*, Microsoft.EntityFrameworkCore.*, Microsoft.Extensions.*, and System.Net.Http.Json package reference's Version attribute to 9.0.0 or later. For example:

<ItemGroup>
-   <PackageReference Include="Microsoft.AspNetCore.JsonPatch" Version="8.0.2" />
-   <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.2" />
-   <PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="8.0.0" />
-   <PackageReference Include="System.Net.Http.Json" Version="8.0.0" />
+   <PackageReference Include="Microsoft.AspNetCore.JsonPatch" Version="9.0.0" />
+   <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.0" />
+   <PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="9.0.0" />
+   <PackageReference Include="System.Net.Http.Json" Version="9.0.0" />
</ItemGroup>

Replace UseStaticFiles with MapStaticAssets

Blazor has different update instructions for MapStaticAssets than Razor Pages and ASP.NET Core MVC.

Blazor web apps

  • Replace UseStaticFiles with MapStaticAssets in Program.cs
  • Update explicit references to static assets in .razor files to use the @Assets["asset-path"] API. This should NOT be done for the Blazor framework scripts (*blazor.\*.js*).
  • Update the root App.razor component to include the <ImportMap /> component in the head.

Razor Pages and ASP.NET Core MVC based apps

Blazor

Blazor migration guidance will appear here prior to the release of .NET 9, which is scheduled for November, 2024.

Additional resources