头图

.NET 6 is the largest version update seen by the ecosystem since the .NET 4 framework. Although .NET Core is a major strategic move that began in 2014, .NET 6 is truly a very important and powerful driving force. Version.

Microsoft MVP Lab Researcher

image.png

.NET 6, which will be officially released on November 9, 2021. Maybe you think that .NET 5 has just been released. I have just started using .NET Core 3.1. .NET6 will be released again. That’s right, .NET 5 is 2020. It was released on November 10, 2019. .NET Core 3.1 was released as early as December 2019. Microsoft has promised to release a version of .NET every year, and .NET 6 is the version released on schedule. There is a support policy corresponding to the release rhythm of this version:
https://dotnet.microsoft.com/platform/support/policy/dotnet-core#cadence

d73595dbe46869c64aa2cddac8b0efec.png
Starting with .NET 5, odd-numbered versions have an 18-month patching cycle, while even-numbered versions have a three-year patching cycle. If you have migrated your application to .NET Core 3.1, please note that it has a three-year patching cycle that will end in December 2022; if you are still on any previous version of .NET Core, you are currently No longer in the support period. Although it has not announced the official end of support for .NET Framework 4.6.2 and later, Microsoft said that .NET Framework 4.8 is the last major version of the .NET Framework and will be updated with the Windows support plan: new feature development should be targeted The platform formerly known as .NET Core (eg .NET 6).

.NET 6 brings many performance improvements and productivity improvements, and it is also a long-term support version. In each successive version of .NET, .NET has made some impressive improvements in execution speed and memory usage. If you have not been tracking, you are likely to be blown away by the cumulative benefits of the .NET framework. For this, you can take a look at the test report of Techempower. For details, please refer to:

https://www.techempower.com/benchmarks/#section=data-r20&hw=ph&test=composite

dramatic change

We start with .NET 5 and look forward. As a long-term support (LTS) version, .NET 6 represents a further improvement, and has a lot of design and performance improvements. We will mainly look at the list of performance improvements in ASP.NET 6 runtime and the interrupt changes in .NET 6. You can see that the changes are very large.

C# language update

The latest version of the C# language is 10.0. There are several interesting changes. For the neat csharper, the global reference (Global using) and the file-wide namespace are very complementary. Now, you can declare the global usage applicable to the entire compilation unit (probably the project), and avoid adding the same set of instructions to the top of each file. File-wide namespaces also allow you to declare a namespace that applies to all code in a given file, no single line, no more matching curly braces, and fewer dent levels in the source file.

before

CSharp9_Widget.cs

using System;
using System.Collections.Generic;
using System.Linq;

namespace MyNamespace.Data
{
  class Widget
  {
    private List<WidgetPart> _widgetParts;
    public IEnumerable<WidgetPart> RequiredParts => 
      _widgetParts;

    public bool RequiresPart(int partId) => 
      _widgetParts.Any(x => x.Id == partId);
  }
}

CSharp9_WidgetPartsInventory.cs

using System;
using System.Collections.Generic;
using System.Linq;

namespace MyNamespace.Data
{
  class WidgetPartsInventory
  {
    private Dictionary<int, WidgetPart> _widgetPartsById;

    public bool HavePartsToBuildWidget(Widget widget) => 
      widget.RequiredParts.All(p => 
        _widgetPartsById.ContainsKey(p.Id));
  }
}

now:

CSharp10_GlobalUsing.cs

global using System;
global using System.Collections.Generic;
global using System.Linq;

CSharp10_Widget.cs

namespace MyNamespace.Data;

class Widget
{
  private List<WidgetPart> _widgetParts;
  public IEnumerable<WidgetPart> RequiredParts => _widgetParts;

  public bool RequiresPart(int partId) => 
    _widgetParts.Any(x => x.Id == partId);
}

CSharp10_WidgetPartsInventory.cs

namespace MyNamespace.Data;

class WidgetPartsInventory
{
  private Dictionary<int, WidgetPart> _widgetPartsById;

  public bool HavePartsToBuildWidget(Widget widget) => 
    widget.RequiredParts.All(p => 
      _widgetPartsById.ContainsKey(p.Id));
}

There are other updates related to records, patterns, and interpolated strings, but most of these updates are syntactic sugar.

ASP.NET Core updates

If you read the description of each version, it is easy to see that ASP.NET Core is a core, from web host and minimal API, hot reload to blazor, there are many interesting features.
Machine and minimal API, hot reload to blazor have many interesting features.

Web host and minimal API

Starting from ASP.NET Core, each application has split the application initialization code into Program.cs (used to create a Web host) and "Startup.cs (used to configure routing and IoC container configuration and other application issues), Usually contains two separate classes. Especially the Startup class has a magical feeling, its methods have never been directly called by the developer. Instead, WebHost automatically calls the configuration method behind the scenes.

The ASP.NET team analyzed this design, and compared with other web frameworks, thought that the setting involved too much. Therefore, the minimal API concept was born. Now, application initialization can all be contained in one file. And you may be surprised that the Main method is not needed anymore. Routes can be defined in the application settings, which greatly reduces the amount of code to start and run an application.

var builder = WebApplication.CreateBuilder(args);

var app = builder.Build();
app.MapGet("/", () => "Hello World!");
app.Run();

Of course, if you still like the organizational style that separates the service settings from the application configuration, you can still create extension methods for IServiceCollection and IApplicationBuilder and call them from the builder and application objects.

Hot Reload

For several years, many Javascript frameworks have supported hot reloading, and now it has become the standard configuration of ASP.NET Core applications in C#: through hot reloading, you can edit your C# code while the application is running (under the debugger), And your code changes will be automatically reflected in your application without losing the application state. In other words, the application does not need to be restarted. For debugging and interactive development workflow, this should be a good improvement. This feature is very important for development. It is this small feature that Microsoft has recently angered the open source .NET community. The good news is that Microsoft has listened to the voice of the community and restored the support for HotReload through CLI. For details, see:
https://www.cnblogs.com/shanyou/p/15450214.html

Blazor

There are a lot of updates in ASP.NET Core 6 about Blazor. For example, Blazor applications can now be directly compiled to WebAssembly to increase application speed on the same code in the IL interpreted (ie. NET natively compiled) version. The local compilation/debugging experience is still fast, because the long compilation time only applies to packaging/release. Speaking of performance, Blazor WebAssembly enables multithreading of client code. Javascript is subject to single thread in the browser. True multithreading opens up some new possibilities for applications that can benefit from parallel processing (of course, this depends on browser support).

There is also a very interesting feature that makes Blazor available for writing desktop applications through MAUI. The biggest advantage of Blazor is that developers can write Web applications entirely in C#, without having to switch to Javascript in order to write the front-end. If there is no additional seam between C# and Javascript, there is no need for a mapping layer between front-end and back-end code. The same C# model can be used on both sides, which means less code is required and therefore less time is required to develop the application. The Blazor desktop further extends this concept to allow this shared code to now also be seamlessly integrated with desktop applications.

MAUI

MAUI is the abbreviation of Multi-platform App UI, and is Microsoft's next attempt at a cross-platform UI framework. MAUI is the evolution of Xamarin and also includes the desktop platform. It allows targeting iOS, Android, macOS and Windows from a single code base. MAUI handles the abstraction of native platform APIs, so you can access content such as device sensors in a platform-independent way. One impression of Xamarin is that they end up with very few interfaces, and they don't look good on any platform. How MAUI will solve this problem remains to be seen. If you are concerned about the speed of development and maintenance costs across multiple platforms, then MAUI is worthy of careful study. MAUI will be officially released in the second quarter of 2022. It is recommended to take a wait-and-see approach and make small attempts to understand the long-term development direction of the platform before it is fully adopted.

Microsoft's Most Valuable Expert (MVP)

bc93fde364ea9dd3d9106b58e805b770.png

Microsoft's Most Valuable Expert is a global award granted by Microsoft to third-party technology professionals. For 28 years, technology community leaders around the world have won this award for sharing their expertise and experience in online and offline technology communities.

MVP is a rigorously selected team of experts. They represent the most skilled and intelligent people. They are experts who are passionate and helpful to the community. MVP is committed to helping others through speeches, forum questions and answers, creating websites, writing blogs, sharing videos, open source projects, organizing conferences, etc., and to help users in the Microsoft technology community use Microsoft technology to the greatest extent.
For more details, please visit the official website:
https://mvp.microsoft.com/zh-cn


Here are more Microsoft official learning materials and technical documents, scan the code to get the free version!
The content will be updated from time to time!
208f6785e4bc3f899ded709a80dff426.jpg


微软技术栈
423 声望998 粉丝

微软技术生态官方平台。予力众生,成就不凡!微软致力于用技术改变世界,助力企业实现数字化转型。