Introduction

Hey devs !

As you may all know, the new version of .NET, .NET 8, has been released on November 14 2023. A lot of you may have applications still in .NET 6 or earlier.
The end of support date for .NET 6 is November 12, 2024, so it’s good considering migrating your applications right now.
In this article, we’ll see what improvements brings .NET 8, and how to migrate your applications.
Microsoft has done a good job to make it easy for us to migrate from .NET 6 to .NET 8, or .NET 7 to .NET 8 (at least if you don’t rely on a Blazor app…), so we might as well make the most of it 😁

.NET 8 new features and improvements

As usual, this new release of .NET brings numerous enhancements in performance, stability, and security. Let’s break down some of them !

Performance Improvements

.NET 8 introduces thousands of performance improvements across the stack. A new code generator called Dynamic Profile-Guided Optimization (PGO) is enabled by default and can improve the performance of your apps up to 20%. The AVX-512 instruction set is now supported, enabling parallel operations on 512-bit vectors of data.

ASP.NET Core Enhancements

ASP.NET Core 8 offers significant performance improvements, up to 18%, compared to .NET 7. It also streamlines identity for single-page applications (SPA) and Blazor, providing cookie-based authentication, pre-built APIs, token support, and a new identity UI.

.NET MAUI

.NET MAUI has been updated, and it’s now possible to deploy your mobile applications to the latest version of iOS and Android.
If you’re not familiar with MAUI , we’ll try to cover the subject in one of the next posts, especially MAUI Blazor Hybrid which is pretty refreshing. So stay tuned 😉

C# 12

.NET 8 is released with C# 12. In C# 12, any class or struct can now have primary constructors created with a concise syntax, eliminating the need for boilerplate code to initialize fields and properties.

Entity Framework Core 8

Entity Framework Core 8 includes support for complex types for value objects (without identity), for example, Address or Coordinate.

.NET Aspire

.NET Aspire is a new stack for building resilient, observable, and configurable cloud-native applications with .NET.
It is designed to improve the experience of building .NET cloud-native apps, and provides a consistent, opinionated set of tools and patterns that help you build and run distributed apps.

In summary, .NET Aspire aims to simplify the complexity of building cloud-native applications, making it easier for developers to focus on their business logic.

For more detailed information, you can refer to the official .NET 8 documentation .
This feature is pretty young for now, but maybe we’ll try to cover it later !

Migrating your application

Prerequisites

Before starting the application migration process, ensure that you have the following:

  • .NET 8 SDK installed on your machine. If not, you can find it here .
  • A good understanding of your application, including its dependencies and third-party packages, this is crucial.

1: Backup Your Project

Before making any changes, it’s always a good idea to make a backup of your project. This will allow you to revert back to the original version if something goes wrong during the migration process.

2: Update the Target Framework

Open your project file (.csproj, .vbproj, or .fsproj) and find the <TargetFramework> element. Change its value to net8.0.

<TargetFramework>net8.0</TargetFramework>

If your application rely on a global.json file, update the version property to the .NET 8 sdk version:

{
  "sdk": 
  {
    "version": "8.0.100"
  }
}

3: Update Your NuGet Packages

As for any .NET migration, you’ll have to update each Microsoft.AspNetCore.*, Microsoft.EntityFrameworkCore.*, Microsoft.Extensions.*, and System.Net.Http.Json package reference’s Version attribute to 8.00 or later.
For example:

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

In addition, some NuGet packages may not be compatible with .NET 8.
Check the compatibility of all the packages that your application uses. If necessary, update them to a version that supports .NET 8 as they may not be all compatible in their current version.

In case you are migrating a Blazor App, there is a little more work to do 😋
Starting .NET 8, Microsoft recommends using Blazor Web Apps instead of Blazor Server, even if it’s still supported. You’ll have to add some tweaks which are all detailed here .

4: Fix Breaking Changes

Of course, .NET 8 may introduce breaking changes that affect your application ! Review the .NET 8 breaking changes documentation and update your code as necessary.

5: Test Your Application

After updating your application, thoroughly test it to ensure that it works correctly. Pay special attention to areas of your application that were affected by breaking changes.

5: And… Voilà ?

Yup, voilà 😁 No more struggles like the last LTS migration. That’s pretty all you have to do !

Conclusion

Migrating to .NET 8 can provide numerous benefits, including improved performance, new features, and enhanced security.
By following these steps, you can ensure that your migration process is smooth and successful, and that you’re up to date !
Considering .NET 8 is the new .NET LTS version, you’re good for 2 years and a half, as .NET 8 end of support date is planned for November 10, 2026.

If you have any questions or feedback, leave a comment below. 😉

Thank you for reading and happy hacking ! 😊