.NET 7 预览版 2 已发布,NativeAOT 正式可用
?.NET 7 Preview 2?已發布,第二個預覽版包括對 RegEx 源生成器的增強、將 NativeAOT 從實驗狀態轉移到運行時的進展,以及對“dotnet new”CLI SDK 的一系列重大改進。
在此下載適用于 Windows、macOS 和 Linux 的?.NET 7 Preview 2 。
引入新的正則表達式源生成器
?新的正則表達式源生成器(Issues?44676)在不增加啟動成本的情況下,為編譯帶來了性能好處,還提供了良好的調試體驗。
要開始使用新的正則表達式源生成器,只需將包含類型轉換為分部(partial)類型,并使用?RegexGenerator?屬性聲明一個新的分部方法。該方法將返回優化的 Regex 對象,源生成器將自動填充該方法的實現,并在更改模式或傳遞其他選項時自動更新。下面是一個例子:
之前:
public class Foo {public Regex regex = new Regex(@"abc|def", RegexOptions.IgnoreCase);public bool Bar(string input){bool isMatch = regex.IsMatch(input);// ..} }現在:
public partial class Foo // <-- Make the class a partial class {[RegexGenerator(@"abc|def", RegexOptions.IgnoreCase)] // <-- Add the RegexGenerator attribute and pass in your pattern and optionspublic static partial Regex MyRegex(); // <-- Declare the partial method, which will be implemented by the source generatorpublic bool Bar(string input){bool isMatch = MyRegex().IsMatch(input); // <-- Use the generated engine by invoking the partial method.// ..} }NativeAOT 更新
該版本將 NativeAOT 從實驗性的?dotnet/runtimelab 存儲庫中移出并進入穩定的運行時庫?dotnet/runtime?repo,但尚未在 dotnet SDK 中添加足夠的支持,以使用 NativeAOT 發布項目。
SDK 改進
- 新的 CLI 解析器 + 選項卡完成??#2191?
.NET 新命令為許多子命令提供了更加一致和直觀的界面,更新了大量對模板選項和參數的 TAB 補全的支持,在用戶輸入有效參數和選項時提供快速反饋。以下是新的幫助輸出示例:
? dotnet new --help Description:Template Instantiation Commands for .NET CLI.Usage:dotnet new [<template-short-name> [<template-args>...]] [options]dotnet new [command] [options]Arguments:<template-short-name> A short name of the template to create.<template-args> Template specific options to use.Options:-?, -h, --help Show command line help.Commands:install <package> Installs a template package.uninstall <package> Uninstalls a template package.update Checks the currently installed template packages for update, and install the updates.search <template-name> Searches for the templates on NuGet.org.list <template-name> Lists templates containing the specified template name. If no name is specified, lists all templates.新命令名稱
幫助輸出中的所有命令不再具有 -- 前綴,更符合用戶對 CLI 應用程序中子命令的期望。舊版本(--install 等)仍可用于防止破壞用戶腳本,將來會在這些命令中添加過時警告以鼓勵遷移。
Tab 補全
dotnet CLI 在 PowerShell、bash、zsh 和 fish 等流行的 shell 上支持 tab 補全已經有一段時間。然而,實現有意義的補全取決于單獨的 dotnet 命令。對于 .NET 7,新命令學習了如何提供 Tab 補全:
- 可用的模板名稱(在 dotnet new <template-short-name> 中) 
- 模板選項(Web 模板中的模板選項列表) 
- 模板選項的允許值(選擇模板參數上的選擇值) 
?該預覽版本還有大量其他更新項目,詳情請查看更新公告:https://devblogs.microsoft.com/dotnet/announcing-dotnet-7-preview-2/
總結
以上是生活随笔為你收集整理的.NET 7 预览版 2 已发布,NativeAOT 正式可用的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 接口返回json对象出现套娃递归问题 |
- 下一篇: Avalonia跨平台入门第二十二篇之人
