Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the new features of the official version of dotNET 5.0

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "what are the new features of the official version of dotNET 5.0". In the daily operation, I believe that many people have doubts about the new features of the official version of dotNET 5.0. the editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the questions of" what are the new features of the official version of dotNET 5.0". Next, please follow the editor to study!

Today the Microsoft development team announced the release of the official version of .NET 5.0. Major updates include a series of new features and improvements, including Category 9 and Fidel5. ASP.NET Core,EF Core,C#9 and Fidel5 were released at the same time. You can download cross-platform including Windows,macOS and Linux from the official download page and cross-processing architecture including x86 and x64, Arm32 and Arm64.

Windows Visual Studio users need Visual Studio 16.8 or later to support .NET 5.0. for macOS users, they need the latest version of Visual Studio for Mac. VS Code's C # plug-in already fully supports .NET 5.0 and Category 9.

1. NET 5.0highlight

Has brought a number of functional improvements, the most eye-catching of which are:

.net 5.0 has been tested for months through hosting on dot.net and Bing (). The performance and stability have been greatly improved.

New language improvements, such as Top-level programming and recording for Cure 9, provide interactive programming and improve the performance of functional programming on .NET.

The .NET library aspect enhances the performance of Json serialization, regular expressions, and HTTP (HTTP 1.1).

P95 latency has been reduced due to improvements in GC, hierarchical compilation, and other aspects.

Application deployment options are better through ClickOnce client application distribution, single-file applications, reduced container image size, and added Server Core container images.

Windows Arm64 and WebAssembly extend the scope of the platform.

1. Cross-platform and Microsoft support

.net 5.0 has almost the same platform support matrix core as .NET 3.1, which is suitable for Windows,MacOS and Linux operating systems. If the operating system supports the use of .NET Core 3.1, it should be possible to upgrade to .NET 5.0 in most cases. The most important new feature in .NET 5.0 is Windows Arm64.

Three months after the release of .NET 5.0, there will be a LTS version of .NET 6.0. Net 5.0 technical support will last until mid-February 2022. The .NET 6.0 technical support period is three years.

.net 5.0 is Microsoft's first version of the unified platform vision, which can use a set of API, languages and tools for a wide range of application types, including mobile, cloud, desktop and IoT.

The first step in achieving this vision is to integrate .NET repositories, including a large portion of Mono. Providing a repository for the .NET runtime and libraries is a prerequisite for delivering the same product everywhere. It also facilitates a wide range of changes that affect the runtime and libraries that previously had buy-back boundaries. Some people worry that large repo transactions will be more difficult to manage. This is not the case.

In .NET version 5.0, Blazor is the best example of taking advantage of buyback mergers and .NET unification. The runtime and libraries of Blazor WebAssembly are now built from the merged dotnet / runtime libraries. Blazor WebAssembly and Blazor on the server use exactly the same code.

two。 Language function

As part of the .NET 5.0 version, Category 9 and Fidel5 are included in the .NET 5.0 SDK. Visual SDK is also included in 5. 0 SDK. It does not include language changes, but has been improved to support the Visual Basic application framework on the .NET Core.

3. Top-level programming

Top-level programming is a new feature in Category 9. The following demonstration program for led lamp control is an example of official Top-level programming:

Using System; using System.Device.Gpio; using System.Threading; var pin = 18; var lightTime = 1000; var dimTime = 200; Console.WriteLine ($"Let's blink an LED!"); using GpioController controller = new (); controller.OpenPin (pin, PinMode.Output); Console.WriteLine ($"GPIO pin enabled for use: {pin}"); / / turn LED on and off while (true) {Console.WriteLine ($"Light for {lightTime} ms"); controller.Write (pin, PinValue.High) Thread.Sleep (lightTime); Console.WriteLine ($"Dim for {dimTime} ms"); controller.Write (pin, PinValue.Low); Thread.Sleep (dimTime);}

You can see from the example the use of target-typed and the allocation of controller variables by new. The GpioController type is defined on the left side of the definition equation. The type is inferred on the right. The new syntax has to replace the traditional var method.

Top-level programming can also be more complex by defining methods and leveraging types defined in the same or other files.

4. Logic and attribute mode

Category 9 includes support for the new model. The following CCS811 gas sensor program is an example of a logical mode:

Var threshChoice = Console.ReadKey (); Console.WriteLine (); if (threshChoice.KeyChar is 'Y'or 'y') {TestThresholdAndInterrupt (ccs811);}

Another new mode is the attribute mode. You can see several property checks in the Mycroft Information Access 6. 0 example. The following code is taken from the photographed PN532 RFID and NFC reader example:

If (pollingType is not {Length: 15 bytes. Used as two error conditions to test before returning. The test conditions can be written as follows:

Byte []? nullpollingType is null or {Length: > 15}

The other two modes. The first is the Mcp25xxx CAN bus in the logical graph.

Public static byte GetRxBufferNumber (Address address) = > address switch {> = Address.RxB0D0 and 0, > = Address.RxB1D0 and 1, _ = > throw new ArgumentException (nameof (address), $"Invalid address value {address}."),}

The second is a logical mode in the piezoelectric buzzer controller.

If (element is not NoteElement noteElement) {/ / In case it's a pause element we have only just wait desired time. Thread.Sleep (durationInMilliseconds);} else {var frequency = GetFrequency (noteElement.Note, noteElement.Octave); _ buzzer.PlayTone (frequency, (int) (durationInMilliseconds * 0.7); Thread.Sleep ((int) (durationInMilliseconds * 0.3));}

5. Record

Category 9 includes a new class called records. Compared with regular classes, it has many advantages, half of which are related to more concise syntax. The following record is an example of a Bh2745 RGB sensor:

Public record ChannelCompensationMultipliers (double Red, double Green, double Blue, double Clear)

You can assign it a value like this:

ChannelCompensationMultipliers = new (2.2,1.0,1.8,10.0)

6. Nullable assertion improvement

The .NET library now fully supports nullable assertions. If nullability is enabled, more type information will be obtained from the platform.

Large classes typically instantiate object members in helper methods called from the constructor. The C # compiler cannot follow the invocation process for object allocation. When you exit the constructor, it assumes that the member is null and uses the warning CS8618. The MemberNotNull property solves this problem. This attribute is applied to the helper method. The compiler will then see that the value is set and realize that the method is called from the constructor.

The following is an example in a BMxx80 temperature sensor:

[MemberNotNull (nameof (_ calibrationData)] private void ReadCalibrationData () {switch (this) {case Bme280 _: _ calibrationData = new Bme280CalibrationData (); _ controlRegister = (byte) Bmx280Register.CTRL_MEAS; break; case Bmp280 _: _ calibrationData = new Bmp280CalibrationData (); _ controlRegister = (byte) Bmx280Register.CTRL_MEAS; break; case Bme680 _: _ calibrationData = new Bme680CalibrationData (); _ controlRegister = (byte) Bme680Register.CTRL_MEAS; break; default: throw new Exception ("Bmxx80 device not correctly configured. Could not find calibraton data. ");} _ calibrationData.ReadFromDevice (this);}

Conditional compilation is used in the actual code. Because the project is multi-objective, and .NET 5.0 + only supports this property. Use this property to skip run-time checking (in the constructor).

7. Application deployment

After you write or update the application, you need to do it for the benefit of the user. This may be to a Web server, cloud service, or client computer, and may be the result of a CI/CD stream using services such as Azure DevOps or GitHub Actions.

.net 5.0, which focuses on improving single file applications, reducing the container size of docker multi-phase builds, and providing better support for deploying ClickOnce applications using the .NET Core.

8. Container

Containers are the most important cloud trend, and multiple levels of the .NET software stack support containers in many ways. The first is basic support, which is increasingly influenced by container scenarios and developers who deploy containerized applications.

It becomes easier to work with the container coordinator. OpenTelemetry support has been added so that distributed traces and metrics can be captured from applications. Dotnet-monitor is a new tool designed to be the primary way to access diagnostic information from .NET processes. In particular, you have started building a container variant of dotnet-monitor that can be used as an application sidecar. Dotnet/tye is also being built to increase the productivity of microservice developers in developing and deploying to Kubernetes environments.

The .NET runtime now supports cgroup v2, which is expected to become an important container-related API after 2020. Docker currently uses cgroup v1 (already supported by .NET). By contrast, cgroup v2 is simpler, more efficient, and more secure than cgroup v1. Linux distributions and container runtimes are. Once it becomes more common, .NET 5.0will work in a cgroup v2 environment.

In addition to Nano Server, Windows Server Core images will also be released. The image supports the following combinations: Windows Server 2019 long service channel (LTSC),. NET 5.0 and x64. There are other changes to reduce the size of the Windows Server Core mirror.

As part of using ".NET" as part of the product name, .NET Core 2.1,3.1 and .NET 5.0 images are now released to the repos series. Released with. NET Core 2.1 and 3.1, and supports multiple versions at the same time. The .NET 5.0 image will be published to a new location. Please update your statements and scripts accordingly.

As part of .NET 5.0, the SDK image is rebuilt on top of the ASP.NET image instead of buildpack-deps to significantly reduce the size of the aggregate image extracted in the multi-phase build scenario.

Ubuntu 20.04 Focal multi-phase build cost:

Download savings: 100 MB (- 30%)

Debian 10 Buster multi-phase build cost:

Net download savings: 146MB (- 40%)

Similar changes have been made to Alpine and Nano Server. Alpine or Nano Server does not have any buildpack-depssdk images. For multi-phase builds, you will see the great success of Alpine and Nano Server as well as 5. 0.

9. Single file application

A single file application is published and deployed as a single file. The application and its dependencies are included in the file. When the application is running, the dependencies are loaded directly into memory from this file (without affecting performance).

In .NET 5.0, single file applications are mainly concentrated on Linux (described later). They can be framework-related or independent. Depending on the global installation of the .NET runtime, a single file application that depends on the framework may be small. The self-contained single-file application is large (because it has a runtime), but does not need to install the .NET runtime as a pre-installation step, so it works properly. In general, relying on frameworks is good for development and enterprise environments, while independent inclusion is often a better choice for ISV.

On all platforms, there is a component called "apphost". This is a file that becomes an executable, such as on Windows or myapp.exe./myapp on a Unix-based platform. For single-file applications, a new application host "superhost" has been created. It has the same role as regular apphost, but also contains a statically linked copy of the runtime. The superhost is the basic design point of the single-file method. This model is used on Linux with .NET 5.0. This method cannot be implemented on Windows or macOS due to various operating system limitations. There is no superhost on Windows or macOS. On these operating systems, native runtime binaries (about 3) are located next to a single file application (resulting in "not a single file").

Framework-related single-file applications:

Dotnet publish-r linux-x64-- self-contained false / p:PublishSingleFile=true

Self-contained single-file applications:

Dotnet publish-r linux-x64-- self-contained true / p:PublishSingleFile=true

You can also use project files to configure individual file releases.

Exe net5.0 linux-x64 true true

10. ClickOnce

ClickOnce has always been a popular .NET deployment option. It is now supported by .NET Core 3.1 and .NET 5.0 Windows applications. When the .NET Core 3.0 adds Windows Forms and WPF support, many people will want to use ClickOnce for application deployment. Over the past year, .NET and Visual Studio teams have worked together to enable ClickOnce publishing on the command line and Visual Studio:

The main deployment models currently supported are framework-related applications. It is easy to rely on the .NET desktop runtime (that is, the runtime that contains WPF and Windows forms).

The biggest change in Mage is that it is now a .NET tool distributed on NuGet. This means that you don't need to install anything special on your computer, just .NET 5.0 SDK to install Mage as a .NET tool. It can also be used to publish .NET Framework applications, but SHA1 signatures and partial trust support have been removed. The Mage installation commands are as follows:

Dotnet tool install-g Microsoft.DotNet.Mage

After you create and distribute the ClickOnce installer, the user will see the familiar ClickOnce installation dialog box.

Second, tool improvement

New improvements to the Windows forms designer, changes to the way the target framework applies to A. NET 5.0 and later, changes to the way WinRT is supported, and other improvements

1. Windows forms designer

The Windows Forms designer (for .NET Core 3.1 and .NET 5.0) has been updated in Visual Studio 16.8 and now supports all Windows Forms controls. It also supports Telerik UI for WinForms controls. The designer includes all the desired designer features, including: drag and drop, select, move and resize, cut / copy / paste / delete controls, integration with property windows, event generation, etc. Data binding and support for a wider range of third-party controls are coming soon.

2. Net 5.0 Target Framework

The new version changes the method used for the target framework. The following project file demonstrates the new .NET 5.0 target framework.

Exe net5.0

So far, the new form is more compact and intuitive than the currently used style. In addition, the target framework is being extended to describe operating system dependencies.

Windows Desktop API (including Windows forms, WPF, and WinRT) is only available on net5.0-windows. You can specify an operating system version, such as net5.0-windows7 or net5.0-windows10.0.17763.0. If you want to use WinRT API, you need to be Windows version 10.

When using the new net5.0-windows TFM, the cross-platform solution may be more challenging. If you want to avoid building for Windows or extracting Windows runtime packages on Linux

3. WinRT Interop (major changes)

On the Windows API theme, a new model has been moved to support WinRT API as part of .NET 5.0. This includes calling API (in either direction; CLR WinRT), marshaling data between the two type systems, and intending to treat them uniformly on the type system or ABI boundaries.

The existing WinRT interoperability system has been removed in .NET 5.0, which is a huge change. This means that applications and libraries that use WinRT and .NET Core 3.x will need to be rebuilt and will not run as is on .NET 5.0. Libraries that use WinRT API will need multiple goals to manage this difference between .NET Core 3.1 and .NET 5.0.

In the future, we will rely on the new CsWinRT tools provided by the WinRT team in Windows. It generates a C #-based WinRT interop assembly that can be delivered through NuGet. The Windows team is doing exactly what WinRT API in Windows is doing. Anyone who wants to use WinRT (on Windows) as an interoperating system can use this tool to expose native API to .NET or .NET API to native code.

The CsWinRT tool is logically similar to TLBIMP and tlbexp, though much better. The tlb tool relies on many COM interop pipes in the .NET runtime. The CsWinRT tool relies only on the public .NET API. That is, the function pointer functionality in Category 9 (partly implemented in the .NET 5.0 runtime) is inspired to some extent by the CsWinRT tool requirements.

This new WinRT interoperability model has several benefits:

Can be developed and improved independently of the .NET runtime.

It is symmetrical with tool-based interoperating systems provided for other operating systems such as iOS and Android.

This tool can take advantage of other .NET features (AOT,C# functionality, IL links), which were not available on previous systems.

Simplify the .NET runtime code base.

You do not need to add a NuGet reference to use WinRT API. It is sufficient for indows 10 TFM (discussed earlier in the.NET 5.0 TFM section). If the target is .NET Core 3.1 or earlier, you need to reference the WinRT package.

4. Native export

Export has been enabled for exporting native binaries, which have called .NET code for a long time. The building block of this scenario is for UnmanagedCallersOnlyAttribute.

.net Native export project support:

Expose custom local exports.

There is no need for advanced interoperability technologies like COM.

Work across platforms.

5. Event pipeline

The event pipeline is a new system and API added in .NET Core 2.2 that can perform performance and other diagnostic investigations on any operating system. In .NET 5.0, the event pipeline has been extended to enable profiler to write event pipeline events. This scenario is critical for profilers that previously relied on ETW (on Windows) to monitor application behavior and performance.

In the new version, assembly loading information can be obtained through the event pipeline. This improvement is the beginning of providing similar diagnostics (as part of the .NET Framework), for example. You can now collect this information using the following command:

Dotnet-trace collect-- providers Microsoft-Windows-DotNETRuntime:4:4--. / MyApp-my-arg 1

The workflow is described in dotnet-trace docs. You can view assembly loading information for a simple test application.

6. Microsoft.Extensions.Logging

The console log provider in the Microsoft.Extensions.Logging library has been improved. You can fully control the format and color of the console output through ConsoleFormatter customization. The formatter API implements rich formatting by implementing a subset of VT-100 escape sequences supported by most modern terminals. The console logger parses escape sequences on unsupported terminals, allowing you to write a single formatter for all terminals.

In addition to supporting custom formatters, a built-in JSON formatter has been added that issues structured JSON logs to the console.

7. Dump debugging

Debugging managed code requires understanding managed objects and constructs. The data access component (DAC) is a subset of the runtime execution engine, which has knowledge of these constructs and can access these managed objects without the runtime. You can now use WinDBG or dotnet dump analyze to analyze the. NET Core process dump collected on Linux on Windows.

Support has also been added for .NET processes running from macOS to capture ELF dump. Because ELF is not a native executable file format on macOS (local debuggers such as lldb will not be able to use with these dump), it is set to select join. To support collection on macOS, set the environment variable COMPlus_DbgEnableElfDumpOnMacOS=1. You can use dotnet dump analyze to analyze the resulting dump.

8. Print environmental information

As .NET expands support for new operating systems and chip architectures, there is sometimes a need for a way to print environmental information. .NET 5 creates a simple .NET tool, dotnet-runtimeinfo, to perform this operation.

You can install and run the tool using the following command.

Dotnet tool install-f dotnet-runtimeinfo dotnet-runtimeinfo

The tool can generate environmental information in formats such as the following.

* * .NET information Version: 5.0.0 FrameworkDescription: .net 5.0.0 Libraries version: 5.0.0 Libraries hash: cf258a14b70ad9069470a108f13765e0e5988f51 * * Environment information OSDescription: Linux 5.8.6-1-MANJARO-ARM # 1 SMP Thu Sep 3 22:01:08 CEST 2020 OSVersion: Unix 5.8.6.1 OSArchitecture: Arm64 ProcessorCount: 6 * * CGroup info** cfs_quota_us:-1 memory.limit_in_bytes: 9223372036854771712 memory.usage_in_bytes: 2740666368

Other updates

1. Windows Arm64

.net applications can now run natively on Windows Arm64. This is the support for Linux Arm64 (support for glibc and musl) added in .NET Core 3.0.

In .NET 5.0, applications can be developed and run on Windows Arm64 devices such as Surface Pro X. You can already run. NET Core and .NET Framework applications on Windows Arm64 through x86 emulation. This is possible, but native Arm64 execution has better performance.

The MSI installer for Arm64 is one of the final changes in this release. The following is the .NET 5.0 SDK installer.

SDK, console and ASP.NET Core applications are supported on Windows Arm64, but not supported by Windows desktop components.

2. ICU is supported on Windows

The ICU library is used for Unicode and globalization support, and was previously used only on Linux and macOS. Now use the same library on Windows 10. This change makes the behavior of globalized API (such as string comparisons for specific cultural regions) consistent between Windows 10MagneMacOS and Linux. ICU is also used with Blazor WebAssembly support.

3. System.Text.Json

Significant improvements have been made in .NET 5.0 in terms of performance, reliability, and ease of adoption for people familiar with Newtonsoft.Json. It also includes support for deserializing JSON objects into records.

When you make an update available, the user will see the update dialog box.

At this point, the study on "what are the new features of the official version of dotNET 5.0" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report