.NET Core 2.2正式發布,有你喜歡的特性嗎?

jopen 6年前發布 | 11K 次閱讀 .Net Core

.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 = ; 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 發行說明

來自: 開源中國社區

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!