From f2a7a0469e5bac26307f77741977be6803a14f38 Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Tue, 13 Jun 2023 11:27:26 -0700 Subject: [PATCH] What's new in Preview 5 (#35761) --- docs/core/whats-new/dotnet-8.md | 95 ++++++++++++++++++++++++++++++--- 1 file changed, 89 insertions(+), 6 deletions(-) diff --git a/docs/core/whats-new/dotnet-8.md b/docs/core/whats-new/dotnet-8.md index 6c2a36504cf88..f562e9be72667 100644 --- a/docs/core/whats-new/dotnet-8.md +++ b/docs/core/whats-new/dotnet-8.md @@ -2,7 +2,7 @@ title: What's new in .NET 8 description: Learn about the new .NET features introduced in .NET 8. titleSuffix: "" -ms.date: 05/16/2023 +ms.date: 06/13/2023 ms.topic: overview ms.author: gewarren author: gewarren @@ -11,7 +11,7 @@ author: gewarren .NET 8 is the successor to [.NET 7](dotnet-7.md). It will be [supported for three years](https://dotnet.microsoft.com/platform/support/policy/dotnet-core) as a long-term support (LTS) release. You can [download .NET 8 here](https://dotnet.microsoft.com/download/dotnet). -This article has been updated for .NET 8 Preview 4. +This article has been updated for .NET 8 Preview 5. > [!IMPORTANT] > @@ -27,6 +27,8 @@ This section contains the following subtopics: - ['dotnet workload clean' command](#dotnet-workload-clean-command) - ['dotnet publish' and 'dotnet pack' assets](#dotnet-publish-and-dotnet-pack-assets) - [Template engine](#template-engine) +- [Source Link](#source-link) +- [Source-build SDK](#source-build-sdk) ### Terminal build output @@ -122,6 +124,14 @@ The [template engine](https://github.com/dotnet/templating) provides a more secu - For `dotnet search` and `dotnet uninstall`, indicate whether a template is installed from a package that's "trusted"—that is, it uses a [reserved prefix](/nuget/nuget-org/id-prefix-reservation). +### Source Link + +[Source Link](../../standard/library-guidance/sourcelink.md) is now included in the .NET SDK. The goal is that by bundling Source Link into the SDK, instead of requiring a separate `` for the package, more packages will include this information by default. That information will improve the IDE experience for developers. + +### Source-build SDK + +The Linux distribution-built (source-build) SDK now has the capability to build self-contained applications using the source-build runtime packages. The distribution-specific runtime package is bundled with the source-build SDK. During self-contained deployment, this bundled runtime package will be referenced, thereby enabling the feature for users. + ## Serialization Many improvements have been made to serialization and deserialization functionality including: @@ -275,6 +285,7 @@ This section contains the following subtopics: - [Performance-focused types](#performance-focused-types) - [System.Numerics and System.Runtime.Intrinsics](#systemnumerics-and-systemruntimeintrinsics) - [Data validation](#data-validation) +- [Metrics](#metrics) ### Time abstraction @@ -402,7 +413,7 @@ IDataView predictions = model.Transform(split.TestSet); } ``` -- The new type is designed to be passed to methods that look for the first occurrence of any value in the passed collection. For example, looks for the first occurrence of any character in the specified array in the `string` it's called on. NET 8 adds new overloads of methods like and that accept an instance of the new type. When you create an instance of , all the data that's necessary to optimize subsequent searches is derived *at that time*, meaning the work is done up front. +- The new type is designed to be passed to methods that look for the first occurrence of any value in the passed collection. For example, looks for the first occurrence of any character in the specified array in the `string` it's called on. NET 8 adds new overloads of methods like and that accept an instance of the new type. When you create an instance of , all the data that's necessary to optimize subsequent searches is derived *at that time*, meaning the work is done up front. - The new type is useful for optimizing format strings that aren't known at compile time (for example, if the format string is loaded from a resource file). A little extra time is spent up front to do work such as parsing the string, but it saves the work from being done on each use. ```csharp @@ -454,14 +465,61 @@ The namesp | New API | Description | |--|--| -| | Validates that structs don't equal their default values. | |
| Specifies whether bounds are included in the allowable range. | | | Specifies both lower and upper bounds for strings or collections. For example, `[Length(10, 20)]` requires at least 10 elements and at most 20 elements in a collection. | | | Validates that a string is a valid Base64 representation. | |
| Specify allow lists and deny lists, respectively. For example, `[AllowedValues("apple", "banana", "mango")]`. | +### Metrics + +New APIs let you attach key-value pair tags to and objects when you create them. Aggregators of published metric measurements can use the tags to differentiate the aggregated values. + +```csharp +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("counter", null, null, new TagList() { { "counterKey1", "counterValue1" } }); +instrument.Add(1); +``` + +The new APIs include: + +- +- +- + ## Extension libraries +### Metrics + +You can register the new interface in dependency injection (DI) containers and use it to create objects in an isolated manner. + +Register the to the DI container using the default meter factory implementation: + +```csharp +// 'services' is the DI IServiceCollection. +services.AddMetrics(); +``` + +Consumers can then obtain the meter factory and use it to create a new object. + +```csharp +IMeterFactory meterFactory = serviceProvider.GetRequiredService(); + +MeterOptions options = new MeterOptions("MeterName") +{ + Version = "version", +}; + +Meter meter = meterFactory.Create(options); +``` + ### ValidateOptionsResultBuilder type .NET 8 introduces the type to facilitate the creation of a object. Importantly, this builder allows for the accumulation of multiple errors. Previously, creating the object that's required to implement was difficult and sometimes resulted in layered validation errors. If there were multiple errors, the validation process often stopped at the first error. @@ -511,7 +569,7 @@ MethodInfo refreshMemoryLimitMethod = typeof(GC).GetMethod( refreshMemoryLimitMethod.Invoke(null, Array.Empty); ``` -## Source generator for configuration binding +## Configuration-binding source generator [ASP.NET Core uses configuration providers](/aspnet/core/fundamentals/configuration/) to perform app configuration. The providers read key-value pair data from different sources, such as settings files, environment variables, and Azure Key Vault. is the type that maps configuration values to strongly typed objects. Previously, the mapping was performed using reflection, which can cause issues for trimming and Native AOT. Starting in .NET 8, you can opt into the use of a source generator to generate the binding implementations. The generator probes for , , and calls to retrieve type info from. When the generator is enabled in a project, the compiler implicitly chooses generated methods over the pre-existing reflection-based framework implementations. @@ -664,13 +722,16 @@ The default console app template now includes support for AOT out-of-the-box. To - SIMD improvements - Support for AVX-512 ISA extensions (see [Vector512 and AVX-512](#vector512-and-avx-512)) - Cloud-native improvements -- Profile-guided optimization (PGO) improvements - JIT throughput improvements - Loop and general optimizations - Optimized access for fields marked with - Consecutive register allocation. Arm64 has two instructions for table vector lookup, which require that all entities in their tuple operands are present in consecutive registers. - JIT/NativeAOT can now unroll and auto-vectorize some memory operations with SIMD, such as comparison, copying, and zeroing, if it can determine their sizes at compile time. +In addition, dynamic profile-guided optimization (PGO) has been improved and is now enabled by default. You no longer need to use a [runtime configuration option](../runtime-config/compilation.md#profile-guided-optimization) to enable it. Dynamic PGO works hand-in-hand with tiered compilation to further optimize code based on additional instrumentation that's put in place during tier 0. + +On average, dynamic PGO increases performance by about 15%. In a benchmark suite of ~4600 tests, 23% saw performance improvements of 20% or more. + ## .NET container images The following changes have been made to .NET container images for .NET 8: @@ -680,6 +741,7 @@ The following changes have been made to .NET container images for .NET 8: - [Preview images](#preview-images) - [Chiseled Ubuntu images](#chiseled-ubuntu-images) - [Build multi-platform container images](#build-multi-platform-container-images) +- [Alpine ASP.NET Docker composite images](#alpine-aspnet-docker-composite-images) ### Debian 12 @@ -727,6 +789,12 @@ RUN dotnet publish -a $TARGETARCH --self-contained false --no-restore -o /app For more information, see the [Improving multi-platform container support](https://devblogs.microsoft.com/dotnet/improving-multiplatform-container-support/) blog post. +### Alpine ASP.NET Docker composite images + +As part of an effort to improve containerization performance, a new ASP.NET Alpine-based Docker image with a composite version of the runtime is available. This composite is built by compiling multiple MSIL assemblies into a single ready-to-run (R2R) output binary. Because these assemblies are embedded into a single image, jitting takes less time, and the startup performance of apps improves. The other big advantage of the composite over the regular ASP.NET image is that the composite images have a smaller size on disk. + +There is a caveat to be aware of. Since composites have multiple assemblies embedded into one, they have tighter version coupling. Apps can't use custom versions of framework or ASP.NET binaries. + ## .NET on Linux ### Minimum support baselines for Linux @@ -741,6 +809,21 @@ In previous .NET versions, you could build .NET from source, but it required you Building in a container is the easiest approach for most people, since the `dotnet-buildtools/prereqs` container images contain all the required dependencies. For more information, see the [build instructions](https://github.com/dotnet/dotnet#building). +## Code analysis + +.NET 8 includes several new code analyzers and fixers to help verify that you're using .NET library APIs correctly and efficiently. The following table summarizes the new analyzers. + +| Rule ID | Category | Description | +|---------|-------------|--------------| +|CA1856 | Performance | Fires when the attribute is not applied correctly on a parameter. | +|CA1857 | Performance | Fires when a parameter is annotated with but the provided argument isn't a constant. | +| [CA1858](../../fundamentals/code-analysis/quality-rules/ca1858.md) | Performance | To determine whether a string starts with a given prefix, it's better to call than to call and then compare the result with zero. | +| [CA1859](../../fundamentals/code-analysis/quality-rules/ca1859.md) | Performance | This rule recommends upgrading the type of specific local variables, fields, properties, method parameters, and method return types from interface or abstract types to concrete types when possible. Using concrete types leads to higher quality generated code. | +| [CA1860](../../fundamentals/code-analysis/quality-rules/ca1860.md) | Performance | To determine whether a collection type has any elements, it's better to use `Length`, `Count`, or `IsEmpty` than to call . | +| [CA1861](../../fundamentals/code-analysis/quality-rules/ca1861.md) | Performance | Constant arrays passed as arguments aren't reused when called repeatedly, which implies a new array is created each time. To improve performance, consider extracting the array to a static readonly field. | +| CA2021 | Reliability | and require compatible types to function correctly. Widening and user-defined conversions aren't supported with generic types. | +| CA1510-CA1513 | Maintainability | Throw helpers are simpler and more efficient than an `if` block constructing a new exception instance. These four analyzers were created for the following exceptions: , , and . | + ## NuGet Starting in .NET 8, NuGet verifies signed packages on Linux by default. NuGet continues to verify signed packages on Windows as well.