In this article, we are going to discuss .NET 7 Preview 6.
follow ASP.NET Core updates in .NET 7 Preview 6 changes.
Microsoft has released .NET 7 Preview 6, just after one month after .NET 7 preview 5.
Below are a couple of enhancements of the .NET 7 Preview.
- Improvement in type converters,
- System.Formats.Tar APIs
- Add JSON contract customization
- Added constraints to NET template authoring
- Some of the performance enhancement
We can download .NET 7 Preview 6, for Windows, Linux, and macOS.
This .Net 7 preview 6 Tested on the visual studio 17.3 preview 3.
Type Converters
Microsoft team did some improvements in primitive types including int128, Uint128, TimeOnly, DateOnly, and Half.
Type Converter's implementation is like the below
Explanation with Example
2. System.Formats.Tar APIs
Microsoft team did some improvement in System.Formats.Tar APIs assembly. This assembly was introduced in Preview 4. it helps us in manipulating TAR archives.
This enhancement was done to cover a couple of special cases
- Writing and reading changes -- The Format property was removed from TarReader because no archive is expected to have all its entries in a single format.
- Entry format, not archive format —- The team discovered that entries of different formats can be intermixed in a single TAR archive, so the LarFormat enum was renamed to TarEntryFormat.
- Global Extended Attributes specialized class — a new class was added to describe a GEA entry.
3. JSON contract customization
Microsoft team did an improvement in JSON contract customization. In some cases, developers need to serialize or de-serialize the JSON, which they don't want to, but they do because either those JSON comes from an external library.
JSON Contract customization allows developers more control over serialized or deserialized.
Now for JSON customization, developers no need to use JsonSerializerOptions.TypelnfoResolver and require assigning resolver.
Developers can use JSON customization by using DefaultJsonTypeInfoResolver and adding their modifier, all modifiers will be called serially,
- When the type is not managed in code should return null.
- Writing custom resolver by using System.Text.Json.Serialization.Metadata.IJsonTypeInfoResolver.
- IJsonTypeInfoResolver can be combined with others resolver which will return first non-null value. example JsonTypeInfoResolver.Combine(new MyCustomeResolver(), new DefaultJsonTypeInfoResolver()).
4. Added constraints to .NET template authoring
Microsoft team did enhancement in .net template authoring using three ways
MultiChoice Parameters:- when we work with choice parameters, now Developers can declare more than one value in a single selection, just like Flags-style enum.
For example,
+availing in multiple forms of authentication on the web template.
+ Choosing multiple target platforms (ios, android, web) at once in the Maui templates.
you can follow the documentation for multi-choice parameters for more details.
> Constraints — .NET preview 6 introduces the Constraints to the .NET template
it allows us to define the context in the template, which helps the developer in the
template engine, to identify which template should show in commands.
for example, dotnet new list.
.NET 7 Preview 6 supports three kinds of constraints:
- Operating System constraints limit templates based on the user OS.
- Installed Workloads constraints require the specified .NET SDK workload which is installed before the template will be available.
- Template Engine Host constraints limit templates based on which host is executing the Template Engine, which is usually the .NET CLI itself, or embedded scenarios like the New Project Dialog in Visual Studio.
- Exit codes unification and reporting -- .NET 7 preview 6 release unifies exit codes reported by the Template Engine, it helps users who depend on scripting in shells to have a more consistent error-handling experience also, errors reported by the .NET CLI now include a link so developers can find more information on each exit code.
.NET 7 preview 6 contains some performance enhancement with respect to CodeGen as well.
- CodeGen: the development team helped out with a couple of community PRs. The Changes affected dynamically PGO (profile-guided optimization), loop optimizations, and Arm64, along with other more general optimizations.
For more information, you can follow the Link