What’s New in .NET 8 Preview 5

.NET 8 Preview 5 was released on 06/13/2023 and introduced several new features and improvements.

New in .NET 8 Preview 5

.NET 8 Preview 5 introduces several updates to the .NET SDK.

This includes an option to simplify the output path and folder structure for build outputs, a new "dotnet workload clean" command, and changes to "dotnet publish" and "dotnet pack" assets.

In addition to these changes to the .NET SDK, improvements have been made to core .NET libraries, extension libraries, and serialization.

A source generator for configuration binding has also been introduced.

Other notable updates include reflection improvements, native AOT support, performance improvements, and changes to .NET container images and .NET on Linux.

Overall, .NET 8 Preview 5 brings a lot of exciting new features and improvements.

One of the improvements is in the Interfaces Hierarchies, .NET 8 has added support for serializing properties from interface hierarchies.

When an object that implements an interface hierarchy is serialized, properties from all levels of the interface hierarchy are included in the serialized data.


IDerivedInterface value = new MyClass { BaseProperty = 0, DerivedProperty = 1 };
JsonSerializer.Serialize(value); // {"BaseProperty":0,"DerivedProperty":1}


public interface IBaseInterface
{
    int BaseProperty { get; set; }
}

public interface IDerivedInterface : IBaseInterface
{
    int DerivedProperty { get; set; }
}

public class MyClass : IDerivedInterface
{
    public int BaseProperty { get; set; }
    public int DerivedProperty { get; set; }
}

Another improvement is the new API Meter.

Metrics are measures of the behavior of a system. They help you understand your system's performance, health, and other aspects. For instance, you might have metrics for how many requests your server handles per second or how long it takes to process each request.

.NET 8 have added the ability to attach key-value pair tags to Meter and Instrument objects when they are created.

With the new API in .NET 8, you can add tags to your Meter and Instrument objects when you create them.

Aggregators can then use these tags to differentiate the values they aggregate. For instance, if you have a tag for "location", you might use it to separate measurements taken in different parts of your system.

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

Meter meter = meterFactory.Create(options);

Instrument instrument = meter.CreateCounter<int>("counter", null, null, new TagList() { { "counterKey1", "counterValue1" } });
instrument.Add(1);

* Sample from Microsoft

See the complete documentation at Microsoft Learn.