lately. NET 6 Preview 1 released NET unification is the core of this version. You can read the original blog:
https://devblogs.microsoft.com/dotnet/announcing-net-6-preview-1/
. NET 6.0 SDK and Runtime download address:
https://dotnet.microsoft.com/download/dotnet/6.0
Next, the author will introduce it to you NET 6 Preview 1 current update content and try some fun updates.
This article is not a translated article, but is made by hand.
Cross platform UI Application
. NET6 unifies multi platform (Android, IOS, etc.) interface applications, provides a consistent experience on multiple platforms and social security, and can share more code between mobile applications and PC desktop applications. The multi platform unified toolkit is based on xamarin The integration and expansion of forms enables us to develop Windows, MacOS, Android and IOS desktop applications.
At present, Visual Studio supports Windows and MacOS, and has been installed in On the NET6 SDK machine, the published desktop program can run on Windows and MacOS. If you want to support Android and IOS, you need to download two other packages. This is because Windows and MacOS can be installed NET6 Runtime to run the program, running is dll file (IL intermediate code), while Android and IOS publish and run native code.
# Windows Download Microsoft.NET.Workload.Android.11.0.200.85.msi Microsoft.NET.Workload.iOS.14.3.100-ci.main.1079.msi # MacOS Download Microsoft.NET.Workload.Android-11.0.200-ci.master.85.pkg Microsoft.iOS.Bundle.14.3.100-ci.main.1079.pkg
Readers can go to https://github.com/dotnet/net6-mobile-samples Find the download link and find that the agent can't download. Please pay attention.
The. NET6 runtime has special tags for Android and ios. To support mobile applications, you need to specify a name. If you want to support Android, you need to In csproj file:
<TargetFramework>net6.0-android</TargetFramework>
Here is a xamarin Forms application csproj template:
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFrameworks>net6.0-android;net6.0-ios</TargetFrameworks> <RuntimeIdentifier>ios-x64</RuntimeIdentifier> <OutputType>Exe</OutputType> </PropertyGroup> <ItemGroup> <PackageReference Include="Xamarin.Forms" Version="4.8.0.1364" GeneratePathProperty="true" /> </ItemGroup> </Project>
Of course, to publish or debug programs, you need SDK or emulator. For example, Android SDK and Android SDK Platform 30 are required for Android. You also need to specify:
dotnet build HelloForms -t:Run -f net6.0-android dotnet build HelloForms -t:Run -f net6.0-ios
In the official sample project, nuget package needs to access Pkgs dev.azure. COM, no agent can't access it. Therefore, this example project can't be done. Just have fun watching it.
At present NET6 Targeting has:
- net6.0
- net6.0-android
- net6.0-ios
- net6.0-maccatalyst
- net6.0-macos
- net6.0-tvos
- net6.0-windows
Blazor desktop app
I think the happiest person to see this update is James Yeung, the leading author of Ant Design of razor project.

In. NET6, blazor extension can be mixed into UI applications, combining Web and native UI, which can be embedded and run in the desktop. Blazor Hybrid Apps refers to Blazor Hybrid Apps.
. NET Core 3.0 supports Blazor Server, 3.1 supports Blazor WebAssembly, and Blazor WebAssembly uses Mono runtime. There are many NETer should have experienced Blazor development. At present, the WebAssembly is still too large (. NET Core 3.x) and has poor performance. follow-up. NET version has been greatly optimized.
In VS2019 Preview4, the template name becomes razor WebAssembly App, which is actually WebAssembly. Adding the name App does not mean that it is a UI program, but it is still a web application.
Back to the point The blog updated by NET6 says that this Blazor can be done together with MAUI, but the blog does not mention the Demo and implementation details. It may still be under development, and Preview 1 may not be available for the time being. After downloading VS2019 Preview4, I still can't create it directly??? Are you kidding me? How to experience this Blazor desktop application?
This Issue was created not long ago: https://github.com/Webreaper/Damselfly/issues/108
However, Blazor can work with mobile applications. There is a project called Mobile Blazor Bindings, which can integrate Blazor into Xamarin. This project is in NET Core 3.x already supports it.
Project address: https://github.com/dotnet/MobileBlazorBindings
Example code:
<StackLayout> <Label FontSize="30">You pressed @count times </Label> <Button Text="+1" OnClick="@HandleClick" /> </StackLayout> @code { int count; void HandleClick() { count++; } }

This kind of project uses Microsoft MobileBlazorBindings. Templates Library, which encapsulates a large number of Razor components.
We can create this kind of project through dotnet command. The corresponding template is as follows:
Template Name Short Name Language Tags ---------------------------------------------- -------------------- ---------- ------------------------ Experimental Mobile Blazor Bindings App mobileblazorbindings [C#] Blazor/Xamarin.Forms Experimental Mobile Blazor Bindings Hybrid App blazorhybrid [C#] Blazor/Xamarin.Forms/Web
Mobile blazorbings is not fun. Don't try it.
We can use the command to create a template project:
dotnet new blazorhybrid
Directory structure: H:. ├─HBlazor │ ├─WebUI │ │ ├─Pages │ │ └─Shared │ └─wwwroot ├─HBlazor.Android │ ├─Assets │ ├─Properties │ ├─Resources │ └─wwwroot ├─HBlazor.iOS │ ├─Assets.xcassets │ ├─Properties │ └─Resources │ └─wwwroot ├─HBlazor.macOS │ ├─Assets.xcassets │ └─Resources │ └─wwwroot └─HBlazor.Windows └─wwwroot
But the official example project has bugs, and the project is inexplicable and abnormal. Just try to play.
This principle is microsoft Mobileblazorbindings encapsulates a series of razor components. Then I write razor files and reference these components to write interfaces and dynamic operations.
Test code (Main.razor):
<ContentView> <StackLayout> <StackLayout Margin="new Thickness(20)" Orientation="StackOrientation.Horizontal"> <Label Text="Fool Gongliang" /> <Image Source="@(new FileImageSource { File = "H:/article/.NET6/mobileblazorbindings/HBlazor/Bugs.jpg" })" /> <Label Text="@($"Bug - {CounterState.CurrentCount}")" FontSize="40" HorizontalOptions="LayoutOptions.StartAndExpand" /> <Button Text="solve Bug" OnClick="@CounterState.IncrementCount" VerticalOptions="LayoutOptions.Center" Padding="10" /> </StackLayout> <BlazorWebView VerticalOptions="LayoutOptions.FillAndExpand"> <HBlazor.WebUI.App /> </BlazorWebView> </StackLayout> </ContentView>
Note: at present, HTML tags such as < br / > are not supported. Razor syntax can be used now, but HTML cannot be used directly. It is speculated that razor may be converted to Xaml, so only the defined components can be used. How to add CSS is also a problem. This also shows that those js are not supported!
And The Blazor desktop apps mentioned in NET6 blog post, according to the interface, should be embedded in the web version. But I can't try it yet, so I can't test it. Skip.
Looking back at cross platform UI applications, we mainly mentioned Xamarin and Blazor, while NET6 will present a new cross platform APP UI framework called MAUI NET MAUI is Xamarin The evolution of forms will appear in 2020. The purpose of this library is to unify the Xamarin SDK to NET, and can share code with other projects (such as Blazor).
There are two ways to try MAUI:
The latter has mentioned that readers interested in MVU can test it by themselves.
Not yet, though NET6 has too little information about Blazor - desktop applications, but we can look at other frameworks, such as LiveSharp.
System.CommandLine
In the past, when we wanted to execute commands, such as viewing the process list and resource consumption on Linux, we would use top -b -n 1. Then we used C# code to represent:
var psi = new ProcessStartInfo("top", "-b -n 1") { RedirectStandardOutput = true }; var proc = Process.Start(psi);
Of course, there are ways, but it seems a little tortuous and difficult to understand. In the previous example code, top is treated as a process and then started with parameters, but it is only suitable for one-time programs. For example, compared with the task manager in Windows, - n 1 means that the output will end after one print. If you call top directly, it will always change dynamically and will not end actively. At this time, problems will occur. The author means that this method is not suitable for interactive programs or command lines. If the called program will not end all the time, it may bring problems to the code; Commands such as cat / etc / OS release and ls -lah are all output at one time. They are easy to handle and will not cause problems.
Another case is to write a command-line program. For example, the author writes a dotnet tool named csys, which can help you view some information of the host. Users can enter commands and parameters, and then judge the functions to be used:
public static class Command { public const string Info = "info"; } Console.WriteLine("Please enter a command"); //Or Main(string[] args) is obtained through args string command = ""; command = Console.ReadLine(); // netinfo if (command == Command.NETINFO) NETINFO();
This method is too stupid, but there is no better way to deal with it.
In order to better cross platform NET6 launched system Commandline package can more easily execute commands and create command-line programs.
This library has many functions. Interested readers can refer to: https://github.com/dotnet/command-line-api
Through this library, we can easily create command-line programs such as wget and curl.
For example, we have written a command-line program for myapp. Users can execute the program as follows:
$> myapp [parse] --int-option not-an-int --file-option file.txt
To handle these parameters, we use string [] and if, which seems less flexible. System. There is an option < T > in commandline to help programmers handle these parameters better:
// Create a root command with some options var rootCommand = new RootCommand { new Option<int>( "--int-option", getDefaultValue: () => 42, description: "An option whose argument is parsed as an int"), new Option<bool>( "--bool-option", "An option whose argument is parsed as a bool"), new Option<FileInfo>( "--file-option", "An option whose argument is parsed as a FileInfo") };
For example, new option < int >, which means that if the parameter -- int option is recognized, the value followed is a numeric type, for example:
--int-option 123
Getdefaultvalue: () = > 42 sets a default value. If it is not set when the user starts the command, the default value is used.
If this parameter is not filled in, the default value of option < T > will be used this time, for example:
# Without any parameters $> myapp
C # code for handling these parameters:
// Note that the parameters of the handler method are matched according to the names of the options rootCommand.Handler = CommandHandler.Create<int, bool, FileInfo>((intOption, boolOption, fileOption) => { Console.WriteLine($"The value for --int-option is: {intOption}"); Console.WriteLine($"The value for --bool-option is: {boolOption}"); Console.WriteLine($"The value for --file-option is: {fileOption?.FullName ?? "null"}"); });
Output result:
The value for --int-option is: 42 The value for --bool-option is: False The value for --file-option is: null
For example code or program, please refer to: https://github.com/dotnet/command-line-api/blob/main/docs/Your-first-app-with-System-CommandLine.md
Other updates
Other updates are mainly about words. The author sorted out some eye-catching information:
-
Arm64
. NET5 has made a lot of performance improvements to the Arm64 version NET6 continues to improve performance;
The plan supports running WPF on Windows Arm64 machine;
It provides support for Apple Silicon (Arm64) chip (native and simulation); -
Container (Docker)
The container is optimized NET program performance;
Optimized official image volume (PGO Technology);
Various ways to improve startup and throughput performance;
Updated the version of the basic image; -
System.Numerics
A set of new mathematical API s to improve the performance of processing mathematics and improve the performance according to hardware; -
Improve single file volume
The published binary files can be packaged to increase the volume; However, the AOT extreme optimization that has been said before has not yet appeared;
-
Crossgen2
Roslyn is an API set for parsing and compiling C# code in C# and can compile C# code into dll; Crossgen 2 can compile cost machine code instead of DLL and crossgen2 are written in C# and can be bootstrapped; Crossgen2 is only applicable to CoreCLR;
ASP.NET Core
ASP.NET Core's roadmap is independent of NET, you can refer to: https://themesof.net/ , this website is written by Blazor. I don't know why, the web content can't be loaded, and the experience is very unfriendly. You can also see some route plans here: https://github.com/dotnet/aspnetcore/issues/27883
. NET6 main plan contents:
-
Thermal loading
During development, you can update the UI and code of the running program without recompiling, and it is convenient to write Blazor, MVC and API; -
Micro API
The document says this: simplify the construction of API endpoints with less code and rituals. But after checking the Issue, I found that this is just learning or writing a simple API, which can reduce unnecessary dll, reduce the volume;
-
Single document release
Build small, independent high-performance applications and services; -
WebAssembly early (AoT) compilation
At the time of publishing, the data in the Blazor WebAssembly application will be NET code is directly compiled into WebAssembly to significantly improve runtime performance; This can reduce some dll file; -
SPA integration
I don't know what this is. The document says it can work seamlessly with the latest modern front-end JavaScript framework;
-
Blazor hybrid desktop apps
As mentioned earlier, you can use Blazor to develop UI programs with MAUI;
-
HTTP/3
Support HTTP/3; Enhance support;
Let's talk about the current situation NET 6 Preview 1 updated content.
-
Support of iasyncdispose in MVC
Now the iasyncdispose interface can handle resources asynchronously on the controller, page model and view components.
-
DynamicComponent
DynamicComponent is a new built-in razor component that can be used to dynamically render components specified by type.
<DynamicComponent Type="@someType" />
You can pass parameters to rendered components using a dictionary:
<DynamicComponent Type="@someType" Parameters="@myDictionaryOfParameters" /> @code { Type someType = ... IDictionary<string, object> myDictionaryOfParameters = ... }
-
ElementReference
ElementReference is an object used to pass HTML element references. In Js, we can use document Getelementbyid ('someid ') to locate the element, but in Blazor, many components are dynamically combined, so it is difficult to determine whether the ID is unique or accurately located. To solve this problem, Blazor handles it through the @ refelement tag and ElementReferencestruct. Interested readers can view Passing HTML element references.
Now ElementReference provides more convenient processing methods for input components such as InputCheckbox, InputDate, InputFile, InputNumber, InputSelect, InputText, and InputTextArea. For example, set the UI focus on these input components. -
Nullable reference type annotation
This is a very good specification constraint. Now ASP Net core has added these comments to all parts, which can more easily improve the compilation security of the project. Projects that choose to use nullable annotations may be removed from ASP. Net Warning when you see a new build in the. Net core API.
In addition, some updates have been made to EFCore, which has no impact. I won't mention it here.