Menu Close

How to migrate .Net Core 7 to .Net Core 8

In this article, we will learn How to migrate .Net Core 7 to .Net Core 8, We’ll talk about why we need to migrate, and what benefits Net Core 8 provides. Please read my previous article Upload Download and Delete files in Azure Blob Storage using ASP.NET Core and Angular.

You can download the .NET 8 SDK from here or you can use Visual Studio 2022 latest release Visual Studio 2022 17.8 release. If you have already Visual Studio 2022, then you can just upgrade to Visual Studio 2022 17.8 from the Visual Studio installer itself.

The features of .NET 8, as announced on the official Microsoft DevBlog, encompass a myriad of advancements. This release is characterized by thousands of improvements in performance, stability, and security.

.net8

Creating .NET Core 7 Project

Let’s create .NET Core 7 project and then we will see how to migrate to .Net Core 8.

  • Launch the Visual Studio IDE and click on “Create new project”.
  • In the “Create new project” window, select “ASP.NET Core Web API” from the template list.
  • Click Next. In the “Configure your new project” window, specify the name and location for the new project and then click Create.
  • In the “Create New ASP.NET Core Web API” window shown next, select .NET Core as the runtime and .NET 7.0 from the drop-down list at the top. Select “API” as the project template to create a new ASP.NET Core API application. 
  • Ensure that Authentication is set as “No Authentication” as we won’t use authentication either and Click Create.
.Net 7.0 Project Structure

In the above image, we can see now the project targeted to .NET 7. To migrate into .Net 8 we need to install .NET 8 SDK using the below link.

https://dotnet.microsoft.com/en-us/download/dotnet/8.0

.Net8 SDK download

Currently, I’m using Windows OS 64-bit system so accordingly I downloaded the highlighted.

After downloading the file install this SDK by following the ongoing installer process.

.Net SDK installer

After the installation, we can verify using the below command to see if SDK version 8 is installed.

dotnet sdk
dotnet sdk

Migrate to .NET 8.0 Project

Right-click on the Project change the target framework .NET 7.0 to .NET 8.0 and save it.

.net 8.0 target-framework

To see the.NET 8.0, right-click on the project and select Edit Project File. We can confirm that the.NET 8.0 has been upgraded using the setup shown below.

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

  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <RootNamespace>Migrate_NetCore_7_8</RootNamespace>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.1" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
  </ItemGroup>

</Project>

What’s new in .NET 8.0?

On November 14th, 2023, Microsoft published and introduced.NET 8, the most recent Long-Term Support (LTS) version of its primary programming platform. .NET 8 introduces major performance, stability, and security improvements. It also includes changes to platforms and tools, which promote better developer efficiency and innovation velocity.

.NET’s latest release transforms the landscape of developing intelligent, cloud-native applications and high-traffic services that scale dynamically. Whether you deploy on Linux or Windows, use containers, or prefer a cloud app model 8 makes it easier to design such applications. It includes a collection of established libraries used by several of Microsoft’s high-scale services. These libraries address fundamental concerns like observability, robustness, scalability, management, and more.

Key Features of .NET 8:

C# 12

  • .NET 8 release 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.
  • Additionally, we can use new default values for parameters in lambda expressions, which enhance code expressiveness.
  • You don’t need more overloading or null checks to handle optional arguments.
  • Moreover, can use the using directive to alias any type, not just named types.

ASP.NET Core 8

  • In ASP.NET Core 8 application you can see significant performance improvements, up to 18%, compared to .NET 7.
  • Native Ahead-of-Time (AOT) support for producing self-contained apps compiled into native code, resulting in smaller deployment size, quicker startup, and reduced memory usage.

Entity Framework Core 8

  • Entity Framework Core 8 supports complex types for value objects (without identity), for example, Address or Coordinate is included.
  • You can find the added support for lazy-loading of no-tracking queries for your program.

Performance Enhancements

  • Introduction of Dynamic Profile-Guided Optimization (PGO), optimizing code based on real-world usage, improving app performance by up to 20%.
  • Rewriting certain methods for better performance, including List<T>.AddRange(IEnumerable<T>) and Int32.ToString().

Cloud-Native Stack (.NET Aspire)

  • .NET Aspire is another cool feature added in the .NET 8.
  • The .NET 8 has the first preview of .NET Aspire, an opinionated stack for building resilient, observable, and configurable cloud-native applications.
  • You can develop specific components for cloud-native development, such as a dashboard, telemetry, configuration, health checks, orchestration, etc.

Getting started with the cloud-native app with .NET Aspire can be found here.

Artificial Intelligence

  • .NET 8 makes ease of use of AI via first-class out-of-the-box AI features in its SDK.
  • .NET 8 brings several enhancements to the System.Numeric library to enhance compatibility with Generative AI into .NET application. You can infuse AI into your .NET applications easily.
  • Large language Model integration with semantic Kernel.
  • It is simple to get started with Azure Open AI and Azure Cognitive Search SDKs in .NET 8.

Blazor Enhancements

  • Now, you can use Blazor for both client-side (Blazor WebAssembly) and server-side (Blazor Server) rendering in the same app.
  • It supports stateless server-side rendering, streaming rendering, progressive enhancement for navigation and form handling, and interactivity per component.

.NET MAUI

  • .NET MAUI is Successor to Xamarin.Forms, enabling the creation of projects for different platforms (WinUI, Mac, iOS, Android) with a single codebase.
  • .NET MAUI supports targeting iOS-like platforms.
  • .NET 8 release has introduced a new Visual Studio Code extension for .NET MAUI.
  • Elevated performance, reliability, and developer experience for .NET MAUI applications

Garbage collection

Starting with .NET 8, you can regulate memory limits. This feature may be useful for cloud services. For example, you can reduce the amount of memory available when the load is low. To adjust the limits, call the RefreshMemoryLimit method.

You can now also update some GC configuration settings. For example, it’s possible to set a hard limit for a heap size:

AppContext.SetData("GCHeapHardLimit", _memoryLimit);
GC.RefreshMemoryLimit();

Conclusion

In this article, we discussed How to migrate .Net Core 7 to .Net Core 8. When compared to the features included in.NET 7,.NET 8 appears to be very similar.

However, I can tell you that there will be plenty of improvements. This time, it appears that the devs were more focused on making targeted platform enhancements. There are numerous little but significant improvements in various areas of.NET usage.

Leave behind your valuable queries and suggestions in the comment section below. Also, if you think this article helps you, do not forget to share this with your developer community. Happy Coding 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *