当前位置:网站首页>Guanxuan.net RC 2

Guanxuan.net RC 2

2021-11-25 18:05:00 MSReactor

We are happy to announce .NET 6 RC(Release Candidate) 2. It is supported in two production environments "go live" The second of the candidate versions . In the past few months , The team has been focused on quality improvement . There are many new features in this version , But we won't fully integrate them until the end . The team is currently validating the end-to-end workflow , To find places where the design intent and technical reality have not yet fully matched . This causes the maintenance staff in the team to modify bug To achieve this goal .

We heard from users , Upgrade the production site to .NET 6 Both " boring "( Non event ) also " It's exciting "( Significant performance improvements ) Of . No accident , We believe that RC2 This trend will continue .

You can download for Linux、macOS and Windows Of  .NET 6 Release Candidate2.

see also  .NET MAUI and  ASP.NET Core post , Learn about clients and Web More details about what's new in the application scenario .

.NET The conference is a free , A three-day virtual developer activity , To celebrate .NET Major version of . This year, ,.NET 6 Will be in 11 month 9 solstice 11 in .NET Released at the conference . We expect you to   Write down the date and listen on time .Visual Studio 2022 preview 5 Also released today , They also announced that they would 11 month 8 Release activities will be held on the th . You can go to  Visual Studio Blog Read all the relevant content on .

We are in this interesting part of the cycle of supporting the production of new versions . We sincerely encourage it . If you need guidance on how to deal with it , Can pass dotnet@microsoft.com Contact us . Many enterprises have begun to contact , Some are already in production . We also help Microsoft Team in RC Run... On version . some Microsoft The team is already RC1 Put into production , We are looking forward to RC2 More help on . This includes  .NET Website .

.NET 6 RC2 Has been tested , And got  Visual Studio 2022 Preview 5 Support for , Also released today .Visual Studio 2022 Will support .NET 6, and Visual Studio 2019 I won't support it . Again ,MSBuild 17.x Will support it , and 16.x I won't support it . If you want to use .NET 6, You need to upgrade to Visual Studio 2022.

Support Mac Version of Visual Studio 2022 At present with .NET 6 RC2 Are not compatible . We're working on this .

View new   Dialogue post , Just the latest .NET Function engineer to engineer in-depth discussion .

 .NET 6 RC1 post Focus on basic functions , Many of these functions need to go to .NET 7 To fully realize . This article focuses on C# 10 And template related improvements . It also includes macOS and Windows Arm64 Update ( Including major changes ). Let's see .

C#10

 C# 10 yes .NET 6 An important part of the version . For the most part ,C# 10 It's about existing concepts and functions ( Such as records and patterns ) Further evolution of . It also includes some features —— Global use and file scope namespace —— It can help you simplify your code and write fewer template files . These specific improvements are the basis for the template changes discussed later in this article . You can go to  .NET 6 An example of See the example used in this section . I will be in .NET 6 Add more examples in the last post of .

Record structs
C# 10 Added to Record structs Support for . This new feature is similar to C# 9( Class based ) Record , But there are some main differences . in the majority of cases , add to Record structs For integrity , In this way, the structure can enjoy the same recording advantages as the class . However , The team did not simply structure the records , Instead, it decided to record the structure with ValueTuple bring into correspondence with , It's like matching class records . Because of this design method ,Record structs The properties of are mutable by default , and Record Class properties are immutable . however , You can declare a read-only Record structs, It is immutable , And match the record class semantics .

At a higher level ,Record structs It will not replace Record class , We also do not encourage Record Class to Record structs. Use class vs Structural guidance also applies to Record Classes and Record structs. let me put it another way , In choosing to use Record Before , You should choose between classes and structures .

Let's see Record structs And  Record class What's the difference?

Battery battery = new("CR2032", 0.235, 100);
WriteLine(battery);
while (battery.RemainingCapacityPercentage > 0)
{
    battery.RemainingCapacityPercentage--;
}
WriteLine(battery);
public record struct Battery(string Model, double TotalCapacityAmpHours, int RemainingCapacityPercentage);

  
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.

This Record structs The example of produces the following results

Battery { Model = CR2032, TotalCapacityAmpHours = 0.235, RemainingCapacityPercentage = 100 }
Battery { Model = CR2032, TotalCapacityAmpHours = 0.235, RemainingCapacityPercentage = 0 }

  
  • 1.
  • 2.

As mentioned earlier , The most obvious difference is that the record structure properties are variable by default . This is the main difference between structure and record structure syntax . I also rewritten this example with a read-only record structure , As shown below .

Battery battery = new("CR2032", 0.235, 100);
WriteLine(battery);
while (battery.RemainingCapacityPercentage > 0)
{
    Battery updatedBattery = battery with {RemainingCapacityPercentage = battery.RemainingCapacityPercentage - 1};
    battery = updatedBattery;
}
WriteLine(battery);
public readonly record struct Battery(string Model, double TotalCapacityAmpHours, int RemainingCapacityPercentage);

  
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.

You'll see it almost with   I am for  C# 9 released ( class )Record Example identical .

Let's review C# 9 The record of . They provide a kind of   The concise syntax is to define data oriented classes with similar structures . They prefer invariance , At the same time, it provides concise Syntax —— With expression —— For immutable friendly replication . People may be surprised that we began to use classes to implement functions similar to structures . Most of the time , Developers use classes instead of structures , This is due to reference passing rather than value semantics . in the majority of cases , Class is the best choice , And it's easy to use .

Structure records are very similar to class records :

  • They use the same syntax ( Except for... In the definition struct or class).
  • They allow custom member definitions ( stay C#10 Newly added ) In the ( By default ) Use fields on property members .
  • They allow the use of init Or variable attributes to customize member behavior .
  • They support expressions . in fact , from C# 10 Start , All structure types support expressions .

Structure records are different from class records :

  • Record structs It can be used Record structs Or read only Record structs To define .
  • Record classes are defined with records or record classes .
  • By default ,Record structs Properties are variable (get/set).
  • By default , Record class properties are immutable (get/init).

Record structs and Record Asymmetry between classes ( No ) Variability may surprise some readers , Even disgust . I'll try to explain   The idea behind the design . Because passing semantics through values , The benefits of structure from non variability are almost as good as classes . for example , If the structure is a key in the dictionary , Then ( A copy of the structure ) The key is immutable , The lookup can only be performed by equality . meanwhile , The design team thinks ValueTuple It can be regarded as an anonymous record structure , and Record structs Can be regarded as ValueTuple Derived from . Only if the record structure contains variability and support fields , That's what works , That's what the team decided to do . in addition , Inclusion variability reflects differences in structures and classes .

If you prefer the immutable behavior of the record structure , You can do this by adding readonly Keyword to get it .

Looking at structs generally, key functionality is common:

  • The equivalence check provided by the runtime is the same for all structures .
  • All structures can be used with expressions to create non mutated copies , This is a C# 10 New features in .

Global usings

global using Enables you to specify a namespace that you want to be available in all source files , Just as it is declared in every source file . It can also be used with static and aliases . This feature allows the use of a common set of using Statement , And expand to more... That are no longer needed using That's ok . This is most relevant to named namespaces , But it can be used in any namespace .

The following syntax can be used in various forms :

  • global using System;
  • global using static System.Console;
  • global using E = System.Environment;

These declarations only need to be declared once in compilation . There are four mode declarations global using.

  • stay Program.cs in , By placing the root using The statement is upgraded to global using Make them global to the whole program .
  • stay globaluses .cs file ( Or a similar name ) in , Centralized management of all global using sentence .
  • In the project file , Use the following syntax .
  • In your project file , Using statements ( For what your application depends on MSBuild SDK) Enable the default platform , The grammar is as follows .

Below MSBuild Grammar can be in ( Use a method similar to the previous example ) Instead of .cs file .

  • < Using Include="System"/ >
  • < Using Include="System.Console" Static="True"/ >
  • < Using Include="System.Environment" Alias="E"/ >

You can go to < PropertyGroup > Enable platform defined implicit using sentence .

  • < ImplicitUsings > enable < /ImplicitUsings >

  Implicitly use different MSBuild SDK.Microsoft.NET.Sdk Defines a basic set , other sdk Define additional sets .

If you use MSBuild function , You can go to obj See valid results in the files generated in the directory , As shown below .

PS C:\Users\rich\app> type .\app.csproj | findstr Using
    <ImplicitUsings>enable</ImplicitUsings>
    <Using Include="System.Console" Static="True"/>
    <Using Include="System.Environment" Alias="E"/>
PS C:\Users\rich\app> type .\obj\Debug\net6.0\app.GlobalUsings.g.cs
// <auto-generated/>
global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
global using global::System.NET.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;
global using E = global::System.Environment;
global using static global::System.Console;

  
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.

You can see ,Microsoft.NET.Sdk stay . globalusings .g.cs Several... Have been added to the file global using sentence . Please note that , Overall :: Operator is not required , To understand the generated Syntax , You can safely ignore it .

File and namespace declarations

The declaration of the file scope namespace is C# 10 Another feature of , Designed to reduce indents and lines .

The syntax of this function is as follows :
namespaceFoo;

It is an alternative to the traditional three line syntax :
namespaceFoo
{
}

Three line syntax can be nested . Single line syntax does not support nesting . Each file can have only one file scope declaration . It must precede all types defined in the file , Much like three line grammar .

Namespace is incompatible with top-level statement . The top-level statement exists in the top-level namespace . It also means , If you ask Program Class to add additional methods , Use partial Kind of grammar , be partial Program Classes also need to be in the top-level namespace .

This feature is very similar to   Add to  C# 8 One way in using Statement .

Const And interpolated string

Now you can assign the interpolated string to const Variable . The use and reading of interpolation strings are very intuitive , Available anywhere . Now? , They can be associated with const Use it together , Provided that the placeholder value is also a constant .

The following example demonstrates a possible example :

const string Bar = "Bar";
const string DoubleBar = $"{Bar}_{Bar}";
WriteLine(DoubleBar);

  
  • 1.
  • 2.
  • 3.

String interpolation has made many other improvements , stay C# 10 and .NET 6 Medium   String interpolation Described in .

Extended attribute mode

You can now reference nested properties or fields in the property schema . for example , The following pattern is now legal :

{Prop1.Prop2: pattern }

before , You need to use a more detailed form :

{Prop1:{Prop2: pattern }}

You can see using this more compact form in the following example , For example, using Reading.PM25.

List<Status> statuses = new()
{
    new(Category.Normal, new(20, false, 20)),
    new(Category.Warning, new(20, false, 60)),
    new(Category.Danger, new(20, true, 60)),
    new(Category.Danger, new(100, false, 20))
};
foreach (Status status in statuses)
{
    string message = status switch
    {
        {Category: Category.Normal} => "Let the good times roll",
        {Category: Category.Warning, Reading.PM25: >50 and <100} => "Check the air filters",
        {Reading.PM25: >200 } => "There must be a fire somewhere. Don't go outside.",
        {Reading.SmokeDetected: true } => "We have a fire!",
        {Category: Category.Danger} => "Something is badly wrong",
        _ => "Unknown status"
    };
    Console.WriteLine(message);
}
record struct Reading(int Temperature, bool SmokeDetected, int PM25);
record struct Status(Category Category, Reading Reading);
enum Category
{
    Normal,
    Warning,
    Danger
}

  
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.

.NET SDK: Modern C# Project template

We are Preview 7 Updated  .NET SDK Templates , Using the latest C# Features and patterns . Important feedback on these changes , Part of the reason is that the build started to fail . As part of the initial template update , We default to .NET6(NET 6.0) project ( Ranging from .NET 5 Update to .NET 6 Applications for ) To enable the   Use... Implicitly ( also called opt-out).  That has changed . We've updated SDK, So all new features are optional . For this change ( stay RC1 In the middle of the world ) The response was positive .

There is also feedback that , Some people don't like the new simplified Program.cs file , Among them is   Top level statement . We've done... On top-level statements   improvement , And continue to use it for templates . We hope that most developers who like traditional methods can directly add additional methods themselves .

The following language features are used in the new template :

  • asynchronous Main
  • Top level statement
  • Target-typed New expression
  • global using Instructions
  • File scope namespace
  • Nullable reference type

We built all these functions , Because we think they are better than the previous alternatives . Templates are the easiest and best way to guide new developers and new applications to the best mode .C# The design team believes in using fewer lines 、 Fewer characters to specify a given concept or operation , And reduce unnecessary duplication . This is what most of these new features support .Nullable The difference is that it produces more reliable code . Each use nullable None of your applications or libraries are likely to crash in production . The software is too complicated , Humans can't see errors like compilers .

A common theme of these functions is , When you view the code in the code editor , They reduce interference and increase hints . Now? , More important aspects will pop up . for example , If you see in a given file using sentence , Then it is a special statement required outside the implicit set . You should be able to copy / Pasting code from one file to another does not require CTRL-. Type to add the required namespace ( At least not so much ). If you see an empty warning or error , You know that your code may be incorrect in some ways . Removing indents also has benefits . More code will be visible in the first dozen columns of the editor , Instead of just filling these columns with space characters . People can think of these characteristics as in the process of transmitting information to the brain , Deliver higher density specificity and significance to the eyes .

Console template

Let's start with the console template . This is very small .

Program.cs:

//  see  https://aka.ms/new-console-template  Get more information 
Console.WriteLine(&quot;Hello, World!&quot;);

  
  • 1.
  • 2.

Project file :

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>
</Project>

  
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.

Although the console template is better than its .NET 5 The corresponding template is much smaller , But there is no reduction in function . You can also see ImplicitUsings Now it's an optional feature , And enabled it in the template .

Web Templates

web The template is also very small .

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

  
  • 1.
  • 2.
  • 3.
  • 4.

webapi The template is closer to the typical ASP.NET Core Applications . You will soon notice Program.cs and Startup.cs The separation between has been deleted . No longer need Startup.cs.

Program.cs:

var builder = WebApplication.CreateBuilder(args);
//  add to  services to the container.
builder.Services.AddControllers();
//  Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();

  
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.

webapi The project file of the template is similar to the console .

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Swashbuckle.AspNetCore" Version="6.1.5" />
  </ItemGroup>
</Project>

  
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.

You can see in this example that the file scope namespace is used , Included in WeatherForecast.cs in :

namespace webapi;
public class WeatherForecast
{
    public DateTime Date { get; set; }
    public int TemperatureC { get; set; }
    public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
    public string? Summary { get; set; }
}

  
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.

The target type new And WeatherForecastController.cs Use it together :

private static readonly string[] Summaries = new[]
{
    "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};

  
  • 1.
  • 2.
  • 3.
  • 4.

stay mvc In the template , You can see the use of nullable annotations and expression body methods .

namespace webmvc.Models;
public class ErrorViewModel
{
    public string? RequestId { get; set; }

    public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
}

  
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.

Windows Forms Templates

Windows Forms The template has also been updated . It includes most of the other improvements involved in other templates , Although not a top-level statement .

namespace winforms;
static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
        ApplicationConfiguration.Initialize();
        Application.Run(new Form1());
    }    
}

  
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.

You can see that a single line namespace statement is used , And because implicit usage is enabled , So there is no platform level using sentence .

WPF The template has not been updated as part of the version .

Use... Implicitly

Now I'll show you the practical application of these features . Let's start with implicit usage . When enabled ,  Every  Sdk Will add their own set of implicit using sentence .

As mentioned earlier ,Microsoft.NET.Sdk Added a few global using sentence .

If this feature is disabled , You will see that the application is no longer compiled , Because no longer declare System Namespace ( In this case ) .

PS C:Usersrichapp> type .app.csproj | findstr Implicit
    <ImplicitUsings>disable</ImplicitUsings>
PS C:Usersrichapp> dotnet build
Microsoft (R) Build Engine version 17.0.0-preview-21501-01+bbcce1dff for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
  Determining projects to restore...
  All projects are up-to-date for restore.
  You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview
C:UsersrichappProgram.cs(2,1): error CS0103: The name 'Console' does not exist in the current context [C:Usersrichappapp.csproj]
Build FAILED.

  
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.

Another option is to use global using characteristic , It allows you to use only the namespace you want , As the following example shows .

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>disable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>
  <ItemGroup>
    <Using Include="System" />
  </ItemGroup>
</Project>

  
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.

Now? , Building code .

PS C:Usersrichapp> type .app.csproj | findstr Using
    <ImplicitUsings>disable</ImplicitUsings>
  <Using Include="System" />
PS C:Usersrichapp> dotnet build
Microsoft (R) Build Engine version 17.0.0-preview-21501-01+bbcce1dff for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
  Determining projects to restore...
  All projects are up-to-date for restore.
  You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview
  app -> C:UsersrichappbinDebugnet6.0app.dll
Build succeeded.
    0 Warning(s)
    0 Error(s)
Time Elapsed 00:00:00.80

  
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.

This is not the recommended generic pattern , But it's a good choice for people who want maximum control . in the majority of cases , We expect developers to rely on SDK The provided implicit use , And from their own code or commonly used NuGet Explicit use of namespaces in packages global using.

Emptiness

I've updated it Program.cs, Used to demonstrate nullable reference types . Application calls List< T > Method , Return to one T?, In this case, it is an nullable string (string?)

List<string> greetings = new()
{
    "Nice day, eh?"
};
string? hello = greetings.Find(x => x.EndsWith("!"));
string greeting = hello ?? "Hello world!";
Console.WriteLine($"There are {greeting.Length} characters in "{greeting}"");

  
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.

Definition hello If the line of the variable is not defined as var, string? perhaps  List< T >.Find return null, Then it cannot be compiled . If not enabled nullable characteristic , I might miss this question , This will cause my code to NullReferenceException Abnormal and collapse . That's not good . I use... On the next line ?? and   Empty merge operator . in the majority of cases , These two lines of code will merge into one line , This is shown in the following code . Consider returning nullable reference types API, I separate them ( In this artificial example ), So that you can see the string?

string greeting = greetings.Find(x =\&gt; x.EndsWith(&quot;!&quot;))??&quot;Hello world!&quot;;

In this case , I merge everything into one line . I can now declare variables as strings , because null Have adapted to ?? String after . character string ? under these circumstances , Only the compiler can see .

string[] args

Now? , I will quickly address most people's concerns about top-level statements ( Include args Parameters ) Questions raised .args Parameters are still available in top-level statements . It's just not that obvious . Here is another program that demonstrates how to use it .

string greeting = args.Length > 0 ? string.Join(" ", args) : "Hello World!";
WriteLine($"There are {greeting.Length} characters in "{greeting}" in this {nameof(Program)}.");

  
  • 1.
  • 2.

It produces the following results .

PS C:\Users\rich\app> dotnet run
There are 12 characters in "Hello World!" in this Program.
PS C:\Users\rich\app> dotnet run Nice day, eh?
There are 13 characters in "Nice day, eh?" in this Program.

  
  • 1.
  • 2.
  • 3.
  • 4.

The application also demonstrates Program Types are still defined . Program.Main No .

By adding a   Global static using To my project file , I started from Program.cs Medium Console.WriteLine Deleted in Console, As shown below .

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>
  <ItemGroup>
    <Using Include="System.Console" Static="True"/>
  </ItemGroup>
</Project>

  
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.

Define general methods

We have heard some feedback from users , They think the real method is better than   Local function , Especially for Program class . You can use any model with top-level statements .

I keep the program unchanged , But switch all functions to Program Static methods in a class , Define... In some classes .

Program.cs.
WriteLine(GetTheGreeting(args));
Program.Foo.cs.
public partial class Program
{
    public static string GetTheGreeting(string[] args)
    {
        string greeting = args.Length > 0 ? string.Join(" ", args) : "Hello World!";
        return $"There are {greeting.Length} characters in "{greeting}" in this {nameof(Program)}.";
    }
}

  
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.

It produces the same result as the previous example .Program.Foo.cs The file name is arbitrary . in fact ,Program.cs So it is with . You can give these documents any name you like . The compiler will find them .

As mentioned earlier , When using top-level statements ,Program The type must be in the top-level namespace .

macOS and Windows Arm64 to update

Except we have good news , There are also some breakthrough changes to share . Support macOS and Windows arm64 The project has been basically completed . stay macOS and Windows With the help of the team , We've been working on it for more than a year . At first , We think the project is just for macOS Upper support Arm64, and Rosetta 2 Will cover x64. It's simple , It's like ISAs, Right ? Not entirely. . With our in-depth study , We found that x64 + Arm64 Coexistence is a bigger task , Mainly focused on CLI And the installer , Including some areas where they need to agree . With the help of RC2, We are delivering .NET Build version of , To provide the best experience we can imagine .

I will quickly summarize what we are doing in macOS and Windows Arm64 machines The process of :

  • .NET 6 RC2 By way of Arm64 and x64 Versions are installed in different locations to achieve Arm64 + x64 coexistence . up to now ,Arm64 and x64 Build mutual coverage ,which led to general sadness.
  • You need to uninstall all .NET Version and start from scratch ( stay macOS and Windows Arm64 On the machine ) To adopt .NET 6 RC2+. This includes Arm64 and x64、.NET 6 and .NET 6 Previous version .
  • .NET 6 The previous version is not ready to install .
  • CLI Allow you to use Arm64 SDK Conduct Arm64 and x64 Development ( Suppose you have installed the required Arm64 and x64 Runtime ). The reverse is the same .
  • We want people to use only Arm64 SDK, Because it will have a better experience ( Native architecture performance ; only one SDK Need to maintain ). We will continue to improve our products , Make this model the first mock exam for most developers. .
  • about SDK, We only in Arm64 Upper support .NET 6+. In the early SDK The build will be in  Arm64 Blocked on .
  • For runtime , We will support all supported versions ,Arm64 and x64.
  • .NET 6 RC2 by Arm64( Include x64 Simulation ) Provides a large number of .NET 6 The final experience .
  • We want to update .NET Core 3.1 and .NET 5 Runtime , In order to .NET 6 RTM bring into correspondence with ( In terms of time and Technology ). This remains to be determined .
  • RC2 The nighttime build is currently bad , So you need to wait a few more weeks , Until we really release RC2 To try all this .
  • in the light of Windows Arm64 Of .NET 5 SDK It will follow .NET 6 RTM And early exit support .

We are also thinking about dotnet test Make some breakthrough changes , To unify our views on architectural goals :

A large part of the project is through Arm64 SDK Enable x64 Runtime . You can see this in the figure below .

 Official announcement  .NET RC 2_.netcore

If you want more details , Please check out  dotnet/sdk #21686.

summary

C# 10 be based on C# 9 Similar features of , It provides significant improvements in simplicity and expressibility . In the past , People can reasonably laugh at C#, Because writing just one line of code requires so much knowledge of etiquette and object-oriented concepts . Those days have passed , The template reflects this . Part of the motivation for these changes is to make C# More attractive to new programmers and schools . These simplified changes fundamentally change how you begin to learn and use C# What is needed . In the new default form , It can be directly compared with other languages that similarly start with a single file source file .

We look forward to seeing other projects pass through top-level statements 、 Global use 、 Records and many other modern features to simplify their new user experience . There are many opportunities to create a simpler learning journey for open source projects and commercial products .

We encourage you to use .NET 6 RC2. We believe you will find it a reliable version . And will The global .NET Conf Date   Will be in 11 month 9 Japan , In order to .NET 6 Release .

Thank you for being .NET Developer .

版权声明
本文为[MSReactor]所创,转载请带上原文链接,感谢
https://chowdera.com/2021/11/20211109095357359Q.html

随机推荐