.NET 8 Preview 5 Features

Jun 8, 2023 | .NET

We’re excited to be here again with a brand new article exploring the latest release of .NET 8 Preview 5. With each new iteration of these previews, Microsoft continues to deliver exciting new advancements to their impressive ecosystem. In this article, we’ll be diving into all the latest features, improvements and optimizations that are included in this fifth release of .NET 8 Preview.

From major performance enhancements to new APIs and tools, there’s certainly a lot to discover.

Let’s take a look at what new features and improvements Microsoft has added in this Preview 5!

Metrics APIs Enhancements

Here begin the first improvements that Microsoft reveals to us. Let’s take a closer look at those improvements.

Dependency Injection (DI) Friendly Metrics APIs

Good news, programmers! The long-awaited IMeterFactory interface is finally here. If you want to create new Meter objects, this is your preview! Now you can finally do it with IMeterFactory.

Let’s check Microsoft Example in this case:

// to understnd, service is the DI IServiceCollection 
// Here register the IMeterFactory in the DI container using the default implementation. 
services.AddMetrics();

Let’s check the next code example:

// Get the meter factory service from the service provider
IMeterFactory meterFactory = serviceProvider.GetRequiredService<IMeterFactory>();

// Define meter options with a name and a version
MeterOptions options = new MeterOptions("MeterName")
{
     Version = "version",
};

// Create a new meter using the factory and options
Meter meter = meterFactory.Create(options);

Instruments and Meters (now with Tags!)

That’s right! Now you can create Meters and Instruments with attached key-value pair tags 🏷️. For those who don’t know, this feature that has been introduced in Preview 5, helps to keep a difference between the aggregate values taking into account the tags.

Let’s check Microsoft Example in this case:

// Define meter options with a name, version, and custom tags
MeterOptions options = new MeterOptions("name")
{
    Version = "version",

    // Attach these tags to the created meter
    Tags = new TagList() { { "MeterKey1", "MeterValue1" }, { "MeterKey2", "MeterValue2" } }
};

// Create a new meter using the factory and options
Meter meter = meterFactory.Create(options);

// Create a counter instrument with custom tags
Instrument instrument = meter.CreateCounter<int>("counter", null, null, new TagList() { { "counterKey1", "counterValue1" } });

// Increment the counter instrument by 1
instrument. Add(1);

SDK Updates

The .NET SDK comes packed with some really cool updates. Let’s explore what’s new.

Source Link Joins Forces with the .NET SDK

No more juggling individual PackageReferences! The .NET SDK now seamlessly integrates Source Link, providing a smooth IDE experience for effortless examination of SourceLinked NuGet Packages 🌟.

Discover New .NET Libraries Analyzers

Remember those invaluable analyzers and code fixers that help us utilize .NET Library APIs effectively? The SDK now features even more of them! Plus, a big shout-out to the awesome community members who contributed to many of these newly added analyzers 🎉.

Framework-Dependent Deployments Take the Lead in .NET 8 Preview 5

With .NET 8 Preview 5, framework-dependent deployments (FDD) are now the default choice. But don’t worry! If you require a self-contained deployment (SCD), options are still at your disposal. Head over to the announcement to learn how to opt-in.

Docker enthusiasts, Get Ready for Exciting Updates!

For all you Docker fanatics, we have some fantastic news in store.

Welcome to the World of Alpine ASP.NET Docker Composite Images

The new Alpine-based composite image has landed, offering a cutting-edge and enhanced version of the ready-to-run compilation.

Termed as “composite,” this approach combines multiple MSIL assemblies into a single, impressive R2R binary. The result? Faster startup times, minimal JIT duration, and smaller R2R image sizes. How cool is that?!

Keep in mind, though, composite images come with tighter version coupling. We’re kicking off with Alpine due to its compact size, but watch this space as we may extend to other image types, like distroless, in the future.

Runtime and Codegen Updates

There’s fabulous news for Dynamic Profile Guided Optimization (PGO) fans: it’s now enabled by default, potentially improving performance by an astounding 5% to 500%! If you have questions on Dynamic PGO, just use <TieredPGO>false</TieredPGO> in your .csproj file to opt-out.

Sure thing! Here’s a revised version with “they” and “Microsoft”:

Turbocharge your code with Dynamic Profile Guided Optimization (PGO)

Hey there, did you know that Dynamic PGO is now enabled by default in C#? Yup, no more fiddling with special settings! This beauty has the potential to improve performance from 5% to a whopping 500%! Of course, the expected bump is around 15%, but that’s still fantastic, right?

Testing showed that 23% of around 4600 tests improved by 20% or more. Giants like Akka.Net, Azure Active Directory Gateway, and Microsoft Graph are already harnessing its power! Got feedback? Go ahead, Microsoft can’t wait to hear it.

Oh, and if you need to opt-out, just add <TieredPGO>false</TieredPGO> to your .csproj, runtime config, or environment.

Elevate your GC-Type game with Enhanced ThreadStatic Field Access

Fantastic update! Optimizations are now available for primitive and reference types in field accesses tagged with ThreadStaticLocal!

Say hello to Arm64 Peephole Optimizations

Arm64 optimizations, anyone? You bet! Starting with Preview 5, embrace these shiny peephole optimizations.

The awesome dev team has replaced str pairs with stp in PR#85032 and switched ldr/str pairs for ldp/stp inside prologs via PR#85657. How wicked is that?

Enhanced Productivity in Visual Studio Code

The C# Dev Kit plugin for Visual Studio Code is here, devs and it’s time to crank up your efficiency. The Test Explorer now has the ability to run tests and provides better code management, AI-assisted suggestions and more!

And there you go, fellow C# enthusiasts! .NET 8 Preview 5 rolls out with even more enticing features and optimizations to elevate your coding experience. Are you as thrilled as we are to explore the latest additions to the .NET ecosystem?

Remember, the clock is ticking! Don’t miss out on getting ahead with the ever-evolving world of .NET 8. Share your thoughts on these enhancements and how they would impact your projects. So, why wait? Put your coding gears on and dive into .NET 8 Preview 5 right now. Happy coding!

You May Also Like

Sign up For Our Newsletter

Weekly .NET Capsules: Short reads for busy devs.

  • NLatest .NET tips and tricks
  • NQuick 5-minute reads
  • NPractical code snippets
.