Discover the New Features of .NET 8: What You Need to Know

.NET 8 is the latest version of the popular crossplatform and open source framework for building applications on Windows, Linux, macOS, and more. It is a longterm support (LTS) release that will be supported for three years. You can download .NET 8 Preview 1 here².

In this article, we will explore some of the new features and improvements that .NET 8 brings to developers. These include:

  1. Terminal build output
  2. Simplified output paths
  3. Improvements in System.Text.Json serialization
  4. GetItems<T>() and Shuffle<T>() methods
  5. Performance improvements
  6. Native AOT
  7. Code generation
  8. .NET container images

Terminal build output

dotnet build has a new option to produce more modernized build output. This terminal logger output groups errors with the project they came from, better differentiates the different target frameworks for multitargeted projects, and provides realtime information about what the build is doing.

To opt into the new output, use the `tl` option. For more information about this option, see [dotnet build options](².

Simplified output paths

.NET 8 introduces an option to simplify the output path and folder structure for build outputs. Previously, .NET apps produced a deep and complex set of output paths for different build artifacts. The new, simplified output path structure gathers all build outputs into a common location, which makes it easier for tooling to anticipate.

To opt into the new output path format, use one of the following properties in your Directory.Build.props file:

Add an ArtifactsPath property with a value of $(MSBuildThisFileDirectory)artifacts (or whatever you want the folder location to be), OR

To use the default location, simply set the UseArtifactsOutput property to true.

Alternatively, run `dotnet new buildprops useartifacts` and the template will generate the Directory.Build.props file for you².

Improvements in System.Text.Json serialization

.NET 8 brings several enhancements to the System.Text.Json namespace, which provides highperformance APIs for working with JSON data. Some of these improvements are:

  • Support for custom converters that can handle polymorphic deserialization
  • Support for deserializing records and initonly properties
  • Support for deserializing anonymous types
  • Support for deserializing fields
  • Support for deserializing nullable reference types
  • Support for deserializing dictionaries with nonstring keys
  • Support for deserializing JSON numbers as strings¹

GetItems<T>() and Shuffle<T>() methods

.NET 8 adds two new extension methods to the System.Linq namespace: GetItems<T>() and Shuffle<T>(). These methods make it easier to work with collections and sequences.

The GetItems<T>() method returns a sequence of items from a source sequence that match a specified predicate. For example, you can use it to get all the even numbers from an array:

int[] numbers = { 1, 2, 3, 4, 5 };
var evenNumbers = numbers.GetItems(n => n % 2 == 0); // returns { 2, 4 }

The Shuffle<T>() method returns a sequence of items from a source sequence in a random order. For example, you can use it to shuffle a deck of cards:

var deck = Enumerable.Range(1, 52);
var shuffledDeck = deck.Shuffle(); // returns { 42, 7, 51, ... }

Performance improvements

.NET 8 continues to deliver on the promise of highperformance applications by introducing various optimizations and enhancements across the framework. Some of these are:

  • Faster startup time with profileguided optimization (PGO)
  • Faster math operations with hardware intrinsics
  • Faster string manipulation with Span<T> and string.Create
  • Faster JSON parsing with SIMD support
  • Faster networking with HTTP/3 and QUIC support
  • Faster garbage collection with concurrent compacting mode

Native AOT

.NET 8 introduces a new way to compile .NET apps to native code: native aheadoftime (AOT) compilation. This feature enables you to produce standalone executables that run without requiring a runtime or any dependencies.

Native AOT offers several benefits, such as:

  • Smaller app size and faster startup time
  • Better compatibility with native libraries and platforms
  • Improved security and reliability
  • Potential performance gains

To use native AOT, you need to install the `nativeaot` workload using the `dotnet workload install` command. Then, you can use the `native` option with the `dotnet publish` command to produce a native executable for your app².

Code generation

.NET 8 introduces a new way to generate code at build time: code generation. This feature enables you to write custom code generators that can produce source files or assemblies based on your project files, metadata, or other inputs.

Code generation can be useful for scenarios such as:

  • Generating boilerplate code or wrappers
  • Implementing source generators or analyzers
  • Creating dynamic proxies or mocks
  • Embedding resources or assets

To use code generation, you need to install the `codegen` workload using the `dotnet workload install` command. Then, you can use the `dotnet codegen` command to run your code generators on your project².

.NET container images

.NET 8 provides new and improved container images for building and running .NET apps on Docker and Kubernetes. These images are based on Alpine Linux, which is a lightweight and secure Linux distribution.

Some of the benefits of using .NET container images are:

  • Smaller image size and faster pull time
  • Reduced attack surface and vulnerability exposure
  • Consistent and reliable behavior across platforms
  • Easier integration with cloudnative tools and services

To use .NET container images, you can pull them from the [Microsoft Container Registry (MCR)]( or build them from the [Dockerfile templates](².


(1) What's new in .NET 8 | Microsoft Learn.

(2) Discover the New Features of .NET 8: What You Need to Know ByteHide Blog.

(3) Announcing .NET 8 Preview 1 .NET Blog

(4) .NET (and .NET Core) introduction and overview | Microsoft Learn.