.NET 7 预览版 2 已发布,NativeAOT 正式可用
?.NET 7 Preview 2?已發(fā)布,第二個預(yù)覽版包括對 RegEx 源生成器的增強(qiáng)、將 NativeAOT 從實(shí)驗(yàn)狀態(tài)轉(zhuǎn)移到運(yùn)行時的進(jìn)展,以及對“dotnet new”CLI SDK 的一系列重大改進(jìn)。
在此下載適用于 Windows、macOS 和 Linux 的?.NET 7 Preview 2 。
引入新的正則表達(dá)式源生成器
?新的正則表達(dá)式源生成器(Issues?44676)在不增加啟動成本的情況下,為編譯帶來了性能好處,還提供了良好的調(diào)試體驗(yàn)。
要開始使用新的正則表達(dá)式源生成器,只需將包含類型轉(zhuǎn)換為分部(partial)類型,并使用?RegexGenerator?屬性聲明一個新的分部方法。該方法將返回優(yōu)化的 Regex 對象,源生成器將自動填充該方法的實(shí)現(xiàn),并在更改模式或傳遞其他選項(xiàng)時自動更新。下面是一個例子:
之前:
public class Foo {public Regex regex = new Regex(@"abc|def", RegexOptions.IgnoreCase);public bool Bar(string input){bool isMatch = regex.IsMatch(input);// ..} }現(xiàn)在:
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 從實(shí)驗(yàn)性的?dotnet/runtimelab 存儲庫中移出并進(jìn)入穩(wěn)定的運(yùn)行時庫?dotnet/runtime?repo,但尚未在 dotnet SDK 中添加足夠的支持,以使用 NativeAOT 發(fā)布項(xiàng)目。
SDK 改進(jìn)
新的 CLI 解析器 + 選項(xiàng)卡完成??#2191?
.NET 新命令為許多子命令提供了更加一致和直觀的界面,更新了大量對模板選項(xiàng)和參數(shù)的 TAB 補(bǔ)全的支持,在用戶輸入有效參數(shù)和選項(xiàng)時提供快速反饋。以下是新的幫助輸出示例:
? 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 應(yīng)用程序中子命令的期望。舊版本(--install 等)仍可用于防止破壞用戶腳本,將來會在這些命令中添加過時警告以鼓勵遷移。
Tab 補(bǔ)全
dotnet CLI 在 PowerShell、bash、zsh 和 fish 等流行的 shell 上支持 tab 補(bǔ)全已經(jīng)有一段時間。然而,實(shí)現(xiàn)有意義的補(bǔ)全取決于單獨(dú)的 dotnet 命令。對于 .NET 7,新命令學(xué)習(xí)了如何提供 Tab 補(bǔ)全:
可用的模板名稱(在 dotnet new <template-short-name> 中)
模板選項(xiàng)(Web 模板中的模板選項(xiàng)列表)
模板選項(xiàng)的允許值(選擇模板參數(shù)上的選擇值)
?該預(yù)覽版本還有大量其他更新項(xiàng)目,詳情請查看更新公告:https://devblogs.microsoft.com/dotnet/announcing-dotnet-7-preview-2/
總結(jié)
以上是生活随笔為你收集整理的.NET 7 预览版 2 已发布,NativeAOT 正式可用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 接口返回json对象出现套娃递归问题 |
- 下一篇: 在.NET 6 中如何创建和使用 HTT