Released in November at .NET Conf 2023, .NET 8 is the latest and greatest version yet, and we are excited to help you get up to speed on what’s new and what's to come.
What to Expect with Each .NET Release
- New version of C#
- ASP.NET Core Improvements
- EF Core Improvements
- Performance Improvements
- Visual Studio Updates
- MAUI / Xamarin Improvements
- … and more!
Support
.NET 8 is a Long-Term Support (LTS) version. Starting with .NET 5, Microsoft has committed to a new versioning and support standard. Every even-numbered release will be considered LTS, while the odd-numbered releases are Standard-Term Support (STS). LTS versions are supported for three years after their release, while STS versions are supported for 1.5. This means that LTS versions will outlive some STS versions. If you are on .NET 6, you still have until November 2024 to upgrade and still be in support. However, if you are on .NET 7, you’ll want to upgrade by May 2024. That’s just a few months away! You can read more here.
C# 12
The preferred language for .NET is C#, and the TLC it receives is a big reason why. Each year, we get new features, syntactic sugar, and improvements. There were many interesting changes to C# this year. Let’s check out some of our favorites.
Primary Constructors
Primary Constructors are pure syntactic sugar. These nifty things allow us to almost treat the body of a class as if it were inside the constructor. Another way to look at it is that our formal parameters from our constructor are now available anywhere within the class body.
It’s important to understand that the parameters in the constructor do not become read-only fields, so there is some risk in using the Primary Constructor, as you see above. This video from Nick Chapsas explains some of the caveats and possible future solutions.
Collection Expressions
Collection Expressions give developers a new way to initialize and combine lists. This feature is new to C#, but may look familiar if you spend time in other languages. In the example below, the nums3 variable ends up being a List<int> with contents 1 2 3 1 2 3 .
Alias Any Type
You may have aliased a class name before if you had two classes with the same name but declared in separate namespaces. Example below:
Alias Any Type expands upon this ability and allows you to alias more than just classes. One great example is aliasing a tuple of 3 ints like below. Link to the docs.
More
- Default Lambda Parameters
- Interceptors
- See it all here
ASP.NET Core 8
Blazor
There were a lot of improvements around Blazor this year. The biggest of which is now the ability to choose between WebAssembly or Web Sockets on a page-by-page basis. Previously, you had to choose between Blazor WebAssembly and Blazor Server before starting your project. .NET 8 changes that and allows you to intermingle both approaches. Frameworks that allow for variable amounts of Server-Side Rendering (SSR) and Client-Side rendering like Next and Nuxt have seen traction recently as there are SEO benefits amongst other niceties that they enable. It’s nice to see Blazor headed in this direction, and it makes it seem like a safer choice in the future.
Native AOT
Not just specific to the web side of things is the boom of Ahead of Time (AOT) related features in .NET 8. The .NET team has been working to make more of the code we write AOT compatible. The way the .NET ecosystem has functioned for a long time has been heavily centered on the idea of Just in Time (JIT) compiling Intermediate Language (IL) code into machine code. This intermediate language is what C# is compiled to and it’s the reason that .NET supports any language that conforms to its spec. The main issue is that JIT can be slow and shipping the .NET Runtime can be a lot of bytes to ship to things like IOT devices. To learn more about Native AOT in ASP.NET Core, read here.
Improved Auth Template
Version 8 brings a new MapIdentityApi extension method that aims to improve the setup of .NET APIs that support SPAs. The pre-existing alternative for this setup brought additional bloat in the form of default views built in Razor Pages. If you are using something like Blazor or a Javascript-based framework, you’ll likely be building the UI portions of the auth experience with those technologies, and this template better suits that flow. Read more here.
EF Core 8
Entity Framework is .NET’s most popular ORM and as the world of data continues to evolve, it’s important that our interaction with it keeps up. Here are some of the newest capabilities.
Complex Types
Complex Types use a class as a grouping of reusable columns for EF. If you wanted to reuse address fields for shipping and billing addresses, you could create a Complex Type named Address and reuse that class in multiple entity types. The use of Complex Types can lead to more concise code and easier mapping. Read more here.
Raw SQL for Unmapped Types
This feature allows users to query the database using raw SQL similar to the way you'd query using the Dapper ORM and also allows mapping the results of the query to a C# class. In previous versions of EF, the class for SqlQuery would need to be mapped to the DbContext via a DbSet. In EF8, unmapped types can also be queried in this way. Read more here.
More
- Primitive Collection Support
- JSON Column enhancements
- DateOnly and TimeOnly support in model building
- Hierarchyid data type support for SQL Server
Performance
.NET 8 boasts over 1250 performance improvements since .NET 7. Each year, there is a comprehensive blog post outlining all of the improvements. As a user of the framework, you often don’t need to understand what all changed, but it’s reassuring that there are people like Stephen Toub who do. Read more here.
Visual Studio
Endpoints Explorer
A new window within VS that will recognize the endpoints your application exposes and give you a visual overview of what’s available. It will even assist you in generating requests for .http files.
Pull Requests within VS
Visual Studio 17.8 now allows you to initiate a PR without leaving the browser. Previously, you would need to go to your source code provider (Azure DevOps, GitHub, etc.) to initiate the PR.
Http Request Engine
Visual Studio now has a built-in editing/executing experience for .http files. For smaller projects, the use of these nifty files may be a new alternative to using something like Postman to make http requests.
MAUI
Microsoft’s Multi-platform App UI (MAUI) is the successor to Xamarin.Forms. It was released alongside .NET 6 and 7 and continues to be an area of focus for the .NET teams. There were many improvements to MAUI that we won’t cover here. The most important thing to be aware of is that Xamarin.Forms support ends on May 1, 2024 so be sure to upgrade to MAUI as soon as possible.
Aspire
A few years back, Microsoft launched a project called .NET Tye. The goal of Tye was to make developing cloud-native apps easier. Tye aimed to do this through abstracting away underlying technologies like Kubernetes away from the developer and streamlining service-to-service communications within a microservices architecture. .NET Aspire is the evolution of Tye and is now available. Aspire is an opinionated framework for building distributed applications. We are excited to see where Aspire goes and learn more as the framework matures. Our very own Kevin has already been diving into this on his blog; if you’d like to see what he has to say, check out aligneddev. Read more from the Microsoft docs here.
Conclusion
There has never been a better time to be a .NET developer. Each year, .NET sees major improvements, and it’s easier than ever to upgrade to the latest version. It is always interesting to see how the .NET team evolves its product to accommodate industry innovations and ever-changing standards. Cloud-native, WebAssembly, and SSR are just a few ways we’ve seen this from .NET this year.
If you need assistance with your .NET Applications, give us a call. Omnitech loves .NET, and we have a wealth of experience in upgrading and building new .NET Apps.