Go back

As many of you may already know, Microsoft releases a new version of .NET every year. At the time of writing, .NET 6 and .NET 7 are the two most recent major releases of Microsoft’s .NET platform. Both releases come with a slew of new features and improvements, but developers should be aware of some differences between the two versions.

Let’s take a closer look at the differences between .NET 6 vs .NET 7.

.NET 6 was released in November 2021, while .NET 7 was released in November 2022.

Performance

This year’s focus is performance. The developers at Microsoft have spent a year refining it, pull request after pull request. They have improved the language-integrated query (LINQ) and just-in-time (JIT) compilation. Among many other things.

1. LINQ

LINQ (Language-Integraded Query) is the name for a set of technologies based on the integration of query capabilities directly into C# language.

With vectorization that makes full use of newer hardware that allows .NET to process multiple pieces of data at the same time. The rapidity of aggregation of LINQ is now faster than it has ever been. As an example, a query that searches the average of an array of 1 million numbers runs almost 26 times faster.

Thanks to .NET being open source, you can check the source code and see that they arrived at that performance using the Vector class.

As many developers use LINQ for a plethora of use cases, it is a big plus for .NET.

The result is astonishingly fast. The time measured here is the time that it took for .NET 6 and .NET 7 to sort an array of 1 000 integers. Almost every aggregation operation of the LINQ is now faster.

2. JIT

JIT stands for “Just-In-Time” and refers to a type of compiler that compiles code at runtime, as it is needed, instead of ahead of time. This can improve the performance of a program by allowing the compiler to optimize the code based on the specific environment in which it is running. Using some complex on-stack replacement.

Stack replacement refers to a technique used to optimize the performance of code execution. When a function is called, the arguments and local variables are typically stored in a stack frame. Stack replacement allows the JIT compiler to replace frequently accessed stack values with registers, which are faster to access. This is done by identifying which stack values are accessed most frequently and allocating registers to hold those values instead. The unused stack locations can then be used to store other data or instructions, leading to more efficient memory use and faster code execution.

Web Development

Both .NET 6 and .NET 7 come with improvements to web development. For example, .NET 6 introduced a new web framework called minimal APIs, which allows developers to quickly build lightweight HTTP endpoints without the need for a full MVC framework. .NET 7 is expected to build on this with more improvements to minimal APIs, as well as other web development features such as improved support for gRPC.

1. Minimal APIs

One of the biggest changes to web development in .NET 6 is the introduction of Minimal APIs.

Minimal APIs are architected to create HTTP APIs with minimal dependencies. This new web framework allows developers to quickly build lightweight HTTP endpoints without the need for a full MVC framework.

With Minimal APIs, you can define your endpoints using simple C# code, making it easy to get started with web development in .NET. They make it ideal for microservices and apps that want to include only the minimum files, features, and dependencies in ASP.NET Core.

.NET 7 builds on the Minimal APIs feature set by adding more capabilities and improvements. Such as endpoint filters, route groups and typed results, which makes minimal APIs even more powerful and efficient. Making it an even more powerful option for building lightweight web applications.

2. Blazor

Blazor is a well-known web development framework that enables developers to create web apps in C# and .NET rather than JavaScript. Blazor received a number of enhancements with.NET 6, including enhanced support for server-side rendering and increased speed. NET 7 continues to improve Blazor, adding new features and additions that might make it even more powerful and user-friendly.

For example, you might use Blazor components from existing JavaScript projects, such as those created using well-known front-end frameworks like Angular, React, or Vue.

Current browsers have APIs for creating custom components that can include UI elements. These customized elements may then be utilized in any web interface.

  • Having also improvements for configuring data binding (Get/Set/After Modifiers).
  • New empty Blazor template to start your project in visual studio.
  • An expanding support of encryption algorithms.
  • New events and authentication requests.
  • Now with no dependency on the Blazor UI component model. You can invoke .NET code from JavaScript using the .NET WebAssembly runtime or use JavaScript functionality from .NET.

3. gRPC

gRPC is a RPC (Remote Procedure Call) open-source framework that allows you to build high-performance, scalable APIs that can be used across multiple platforms and languages. .NET 6 introduced improved support for gRPC, making it easier to build gRPC-based applications with .NET.

.NET 7 continues improving gRPC support, such as:

  • Performance improvements
  • Create RESTful services with gRPC JSON transcoding
  • gRPC apps on Azure App Services

4. OpenAPI

The OpenAPI Specification (OAS) enables REST-compliant APIs to be described, developed, tested and documented. In a word, it’s a specification for a machine-readable interface definition language with the aim of describing, producing, consuming and visualising web services.

.NET 6 introduced built-in support for OpenAPI, making it easy to generate API documentation and test your APIs using Swagger UI.

.NET 7 is expected to continue improving OpenAPI support, with more features and enhancements that could make it even easier to build and document APIs with .NET. In summary, both .NET 6 and .NET 7 offer a number of improvements and enhancements for web development, with features such as Minimal APIs, Blazor, gRPC, and OpenAPI making it easier to build fast, scalable, and efficient web applications with .NET.

Desktop Development

.NET 7 brings significant updates and improvements to desktop (and mobile) development frameworks making them more modern, simple, and fast:

1. WinForms

WinForm (Short for Windows Form Application) is an UI framework for building Windows desktop applications that exist since around 20 years. Microsoft wants to “help Windows Forms developers to modernize their existing apps and to adopt new cloud-based technologies”. One way to do this is to encourage developers to move from the traditional code-behind pattern to the MVVM pattern. This more modern pattern will help developers to extract business logic from code-behind pages and make the code easier to test and more reusable. To further this strategy, WinForms’ data-binding system has been aligned with WPF and Xamarin’s one, technologies already embracing MVVM.

Previously in this article, we discussed JIT compilation. Microsoft encouraged and eased the experimentation of publishing applications with NativeAOT, an alternative to JIT, by adding a single line in the .csproj file. The benefits expected of using this technology are a faster startup time, lower memory usage, and the ability to run the application on any Windows or Linux machine that doesn’t have the .NET runtime installed.

Additionally, Microsoft’s teams and a few community members worked on a lot of other topics. They have modernized the drag-and-drop and dialog functionalities. They have improved the accessibility, visibility, and automation of WinForms controls. And, finally, they have fixed a few rendering issues of WinForms controls. In .NET 7 devblogs, Microsoft has communicated continuing the tedious process of bug-fixing High DPI and scaling issues for special monitors or multi-monitor setups. 

2. WPF

WPF (Windows Presentation Foundation) has also received a couple of updates, which focus on improving performance, accessibility, and bug fixes. The improvement of performance in WPF libraries has been achieved by avoiding the boxing of variables, removing unnecessary objects and collection allocations, and refactoring miscellaneous classes such as wrappers or parsers. This new version of .NET enhances the application accessibility by adding useful new shortcuts, and screen readers now correctly read checkable menu items. Thanks to the community feedback, many bugs have been fixed and Microsoft plans to make internal integration tests public on GitHub, which will allow developers to further improve quality control by adding their own integration tests in this repository. Microsoft’s internal team is very grateful for the community’s involvement and continues to push quality control through basic regression tests on pull requests.

3. .NET MAUI

.NET Multiple-platform App UI is the framework used to build native, cross-platform desktop and mobile apps from a single C# codebase for Android, iOS, Mac, and Windows. A ton of new controls have been added to the young MAUI framework released in April 2022. The long-awaited official Map control has finally become available, making it easier to add a map, markers, polygons, pins, user geolocation, traffic, etc in your mobile and desktop application.

In addition, a TwoPaneView control has been added. This control positions child content side-by-side or vertically and aligns its child contents based on the hinge or the screen fold on foldable Android devices. And many basic UI desktop features have also been added, such as context menus, tooltips, right clicks, pointer gestures, and pointer tracking. More global improvements are also very noticeable, such as the new delegates used in the iOS life cycle and updates of the Window class that allows for more precise management of the application window’s position and size in desktop versions.

MAUI also benefits from the overall performance ups of .NET and gains efficiency when scrolling CollectionViews, layout computations, startup time, application size, navigation between pages and even more. 

Cloud Development/Containerization

Containers are a type of lightweight virtualization technology that allows applications to run in an isolated environment, making it easier to deploy and manage them across different systems. They are becoming increasingly popular in cloud deployments as they offer portability and flexibility, allowing developers to easily move their applications between different cloud providers or environments.

With the release of .NET 7, Microsoft has made it easier to deploy .NET applications into containers without the need for Docker Desktop. This means that developers can now use a simple command line interface (CLI) to customize and deploy their containers, regardless of which container runtime they are using.

Microsoft has brought support into Visual Studio for publishing containerized applications to Azure container Registry. With this support, developers can easily publish their container images to the Azure Container Registry from Visual Studio.

In addition, with the release of .NET 7, Microsoft has made it easier for developers to set up CI/CD workflows through GitHub Actions. With a simple right-click in Visual Studio, developers can create a pre-defined GitHub Actions workflow for building, testing, and deploying their .NET applications.

When an application running on Azure encounters an issue or error, Azure Monitor can capture a dump file containing information about the state of the application at the time of the error. This dump file can then be analyzed using Visual Studio’s diagnostic Tools to identify the root cause of the issue. Finally, there are multiple ways to host container apps in Azure, each with its own benefits and use cases. Some of the most common ways to host container apps in Azure are Azure App ServiceAzure Kubernetes Service, and Azure container Apps which is a newer offering from Microsoft that allows developers to deploy containerized applications directly to Azure.

Conclusion

Should you switch to .NET 7?

.NET 7 is not a long-term support (LTS) release. Microsoft typically provides LTS releases for its .NET frameworks every two years, which come with an extended support period of up to three years. These LTS releases are ideal for applications that require stability and long-term support, as they receive security patches, bug fixes, and other critical updates for an extended period.

In contrast, non-LTS releases like .NET 7 typically have a shorter support period and are intended for users who want to take advantage of the latest features and improvements but are willing to accept the trade-off of a shorter support period.

Therefore, a company should consider the implications of using a non-LTS release like .NET 7. If they require long-term support for their application, they may want to wait for the next LTS release or consider an alternative framework that offers longer support. However, if they prioritize the latest features and improvements, .NET 7 may be a suitable choice for their project.

Other resources: