.NET Core 2.2 正式发布,有你喜欢的特性吗?

微软发布了 .NET Core 2.2 版本,主要包含对运行时的诊断改进,对 ARM32 for Windows 和 Azure Active Directory for SQL Client 的支持。此版本最大的改进是在 ASP.NET Core 中。

ASP.NET Core 2.2 和 Entity Framework Core 2.2 也已发布。

你可以在 Windows、macOS 和 Linux 上下载并开始使用 .NET Core 2.2:

Visual Studio 15.9、Visual Studio for Mac 和 Visual Studio Code 已支持 .NET Core 2.2 。

更新亮点:

分层编译(Tiered Compilation)

分层编译是一种使运行时能够更自适应地使用实时(JIT)编译器,以在启动时获得更好的性能并最大化吞吐量的功能。该功能在 .NET Core 2.1 中是可选的,然后在 .NET Core 2.2 Preview 2 中默认启用。不过开发团队认为还没有准备好在正式的 .NET Core 2.2 版本中默认启用它,所以已将其切换回可选功能。

分层编译有望在 .NET Core 3.0 中默认启用。

运行时事件(Runtime Events)

我们通常需要监视运行时服务(如当前进程的 GC,JIT 和 ThreadPool ),以了解这些服务在运行应用程序时的行为方式。在 Windows 系统上,这通常使用 ETW 监视当前进程的 ETW 事件来完成。虽然这种方法仍然有效,但使用 ETW 并不总是很容易。在一些低权限环境中,或是在 Linux、macOS 上,都可能无法使用 ETW 。

从 .NET Core 2.2 开始,可以使用 EventListener 类来使用 CoreCLR 事件。这些事件描述了 GC,JIT,ThreadPool 和 interop 的行为。它们在 Windows 上作为 CoreCLR ETW 提供程序的一部分公开的相同事件。这允许应用使用这些事件或使用传输机制将它们发送到遥测聚合服务。

订阅事件示例代码:

internal sealed class SimpleEventListener : EventListener
  {
      // Called whenever an EventSource is created.
      protected override void OnEventSourceCreated(EventSource eventSource)
      {
          // Watch for the .NET runtime EventSource and enable all of its events.
          if (eventSource.Name.Equals("Microsoft-Windows-DotNETRuntime"))
          {
                  EnableEvents(eventSource, EventLevel.Verbose, (EventKeywords)(-1));
          }
      }

      // Called whenever an event is written.
      protected override void OnEventWritten(EventWrittenEventArgs eventData)
      {
          // Write the contents of the event to the console.
          Console.WriteLine($"ThreadID = {eventData.OSThreadId} ID = {eventData.EventId} Name = {eventData.EventName}");
          for (int i = 0; i < eventData.Payload.Count; i++)
          {
              string payloadString = eventData.Payload[i] != null ? eventData.Payload[i].ToString() : string.Empty;
              Console.WriteLine($"\tName = \"{eventData.PayloadNames[i]}\" Value = \"{payloadString}\"");
          }
          Console.WriteLine("\n");
      }
  }

SqlConnection 支持 AccessToken

SQL Server 的 ADO.NET provider —— SqlClient,现在支持将 AccessToken 属性设置为使用 Azure Active Directory 以对 SQL Server 连接进行身份验证。要使用此功能,你可以使用 Microsoft.IdentityModel.Clients.ActiveDirectory NuGet 包中包含的 Active Directory Authentication Library for .NET 获取 access token value 。

使用 Azure Active directory 验证 SQL Server 连接示例:

// get access token using ADAL.NET
var authContext = new AuthenticationContext(authority);
var authResult = await authContext.AcquireTokenAsync(appUri, clientCredential);
// setup connection to SQL Server
var sqlConnection = new SqlConnection(connectionString);
sqlConnection.AccessToken = authResult.AccessToken;
await sqlConnection.OpenAsync();

此外,该版本还包含 Injecting code prior to Main,提供 Windows ARM32 支持等特性。

适用平台:

  • Windows Client: 7, 8.1, 10 (1607+)
  • Windows Server: 2008 R2 SP1+
  • macOS: 10.12+
  • RHEL: 6+
  • Fedora: 26+
  • Ubuntu: 16.04+
  • Debian: 9+
  • SLES: 12+
  • openSUSE: 42.3+
  • Alpine: 3.7+

适用芯片:

  • x64 on Windows, macOS, and Linux
  • x86 on Windows
  • ARM32 on Linux (Ubuntu 16.04+, Debian 9+)
  • ARM32 on Windows (1809+; available in January)

完整详细信息请查阅 .NET Core 2.2 发行说明

本文文字及图片出自 OSchina

余下全文(1/3)
分享这篇文章:

请关注我们:

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注