.NET 7 預覽版 2 正式發布:Re醫文gEx 源生(shēng)成器(qì)增強、NativeAOT 更新(x土購īn)
3月(yuè)(yuè)15号, .NET 7 預覽版 2正式業湖發布,距預覽版 1 發布已過去将近一(yī)個(gè錯要)月(yuè)(yuè)的時(shí)間(ji在快ān)。.NET 7 的第二個(gè)預覽版包括對 RegEx 源生(sh弟朋ēng)成器(qì)的增強、将 NativeAOT 從實驗狀态轉子船移到運行時(shí)的進展,以及對“dotnet 做樂new”CLI 體(tǐ)驗的一(yī)系列重大改進。
主要更新(xīn)内容
引入新(xīn)的正則表達式源生(shēng)成器(q計西ì)
新(xīn)的正則表達式源生(shēng)成器(qì)(Issues 44676)在無需增加啟動成本的情況下(xià),為(wèi)編譯帶來(lái笑哥)了(le)許多性能(néng)上(shàng)的好外裡(hǎo)(hǎo)處,還提供了(le)良好(hǎo)(hǎo)的調試體(tǐ大鐘)驗。
要開始使用新(xīn)的正則表達式源生(shēng)成器(qì),隻需将包含場大類型轉換為(wèi)分(fēn)部(part鄉舊ial)類型,并使用 RegexGenerator 屬性聲明一(y秒城ī)個(gè)新(xīn)的分(fēn)部方法。該作小方法将返回優化(huà)的 Regex 房計對象,源生(shēng)成器(qì)将自動填充該來女方法的實現(xiàn),并在更改模式或傳遞其他選項時(shí)自動更新(x答暗īn)。例如(rú):
之前:
public class 內地;Foo{
public Regex&藍弟nbsp;regex = new R友刀egex(@"abc|def", RegexOptions.IgnoreCase);劇暗
public 紙裡;bool Bar(string&nb近在sp;input)
{
 筆街;bool isMatch&n北民bsp;= regex.IsM影吧atch(input);
//&n還近bsp;..
}}
現(xiàn)在:
public partial class Fo長開o // <-- Make&她紅nbsp;the class a pa紙空rtial class{
[RegexGenerat房術or(@"abc|def", RegexOptions.IgnoreCas訊筆e)] // <-- Add&短的nbsp;the RegexGenerator&nb刀煙sp;attribute and工跳 pass in your pattern and 是對;options
public stati體冷c partial Regex&nbs遠小p;MyRegex(); // &nb舞可sp;<-- Declare 師現the partial me工相thod, which will be impleme家就nted by the source generator
public 能房;bool Bar(string inp錢歌ut)
{
b女快ool isMatch = MyRegex(南媽).IsMatch(input);&nb站購sp;// <-- U來玩se the gener慢城ated engine by invokin做遠g the partial method.
/通間/ ..
}}
SDK 改進
新(xīn)的 CLI 解析器(qì) + 選項卡完成 #2191
.NET 新(xīn)命令為(wèi)用戶已經使用的許多白微子(zǐ)命令提供了(le)更加一(yī)緻和直觀的界面。此外,對志拍模闆選項和參數的 TAB 補全的支持已得到大量更新(xīn),在用戶鍵計友入時(shí)對有效參數和選項提供快(kuài)速反饋。以下(xià)快道是新(xīn)的幫助輸出示例:
❯ dotnet new -村門-help
Description:
Template Instantiation下就 Commands for .NET CLI.Usage:
dotnet ne弟們w [<template-short-na了問me> [<template-a家路rgs>...]] [opt中分ions]
dotnet 要能;new [command] [options]Argumen為用ts:
<template-sho什還rt-name> A short哥懂 name of 花個the template to&nbs他煙p;create.
<template-args&g土習t; &nbs民舞p; Temp行時late specific options 化分to use.Options:
-?, -h,木關 --help Show command line help.Commands:
install <也話;package> 農民 Installs&n多書bsp;a template packag木車e.
uninstall <校習package> &nb見子sp;Uninstalls a template&nbs校照p;package.
update&n兵亮bsp; &nbs和場p;  又可; &nb紅醫sp; Checks t門畫he currently&nbs黑購p;installed template&子討nbsp;packages for update, and instal件她l the updates.
search &l技間t;template-name>  工少;Searches for the templates on 刀得;NuGet.org.
list <template-na光腦me> Lists&n笑國bsp;templates containin照話g the specifi看鐵ed template 懂志name. If no&n多雨bsp;name is specified,&nbs草器p;lists all templa外去tes.
新(xīn)命令名稱
幫助輸出中的所有命令不再具有 -- 前綴,這(zhè)更符合用戶對 CLI 海腦應用程序中子(zǐ)命令的期望。舊版本(--install 等)仍可用于防東厭止破壞用戶腳本,将來(lái)會在這(zhè)些(xiē)命令中添加過時站農(shí)警告以鼓勵遷移。
Tab 補全
dotnet CLI 在 PowerShell、ba間吧sh、zsh 和 fish 等流行的 shell我短 上(shàng)支持 tab 補全已經有一照上(yī)段時(shí)間(jiān)了(le)。然而,窗術實現(xiàn)有意義的補全取決于單獨的 dotnet 命兒海令。對于 .NET 7,新(xīn)命令學窗玩習了(le)如(rú)何提供 Tab 補全:
可用的模闆名稱(在 dotnet new <temp照場late-short-name> 中)
❯ dotnet new angular
angular &n離短bsp; &nbs你票p; &山歌nbsp; grpc 明請 黑些 &訊市nbsp; razor&nb東自sp; &資制nbsp;  章村;  吧國; viewstart &什紅nbsp; 媽件 &n購老bsp; worker &nbs水慢p;  月說; &為校nbsp; -h
blazorserver &n數話bsp;  遠風;mstest 林風 森妹 日資 razorcla醫話sslib &nbs些妹p; web &n商光bsp; &nbs慢腦p;  城花; wpf&分湖nbsp;  在錢; &n報就bsp;  玩友; &nbs媽笑p;/?
blazorwasm  音妹; &nbs謝看p; mvc&nb作林sp;  車城; &nbs輛說p; &n科月bsp; razorcomponen老風t  數老; webapi 煙章 &村熱nbsp; &nbs都理p; &nb女市sp;wpfcustomcontrollib&nbs內美p; /h
classlib &nbs化行p; &n男用bsp; &在知nbsp;nugetconfig &nb那用sp; 來可 react &n哥吃bsp; &nb資林sp;  遠業; webapp &n員師bsp; &nb又不sp; 業林 &上遠nbsp;wpflib &nb藍有sp; &n兵暗bsp; &n長村bsp; ins國筆tall
console 麗森 &明快nbsp; nunit &nb看中sp; &n森好bsp; &nbs北月p; reactredux 視亮; &nbs現門p; &nbs校兒p;webconfig  照亮; &n資下bsp; 數森wpfusercontrollib&nb鄉山sp; list
editorconfig &知機nbsp; &能算nbsp;nunit-test &nb畫畫sp; 子厭 sln&nbs麗機p; &海長nbsp; &nbs師理p; &n朋紙bsp; winforms 藍飛 &n長是bsp; &nb光機sp; xunit &歌秒nbsp;  化知; &時銀nbsp; searc會媽h
gitignore &姐制nbsp; &nbs近城p; page 鐘影 &nbs快近p; &弟拿nbsp; t靜市ool-manifest  問年;  公信;winformscontrollib 志自--help &nbs森好p; &nbs地店p; &nb暗會sp; uninstall
globaljson  務匠; &n市答bsp;proto &n子信bsp; 輛呢 &nb船鐵sp; viewimpo們低rts &nbs民快p; winformslib&海資nbsp; &nbs鐘懂p; &n分作bsp;-? &n分唱bsp;  有子;  問去; 森子update
模闆選項(Web 模闆中的模闆選項列表)
❯ dotnet new 兵子web --dry-run
--dry-run &nb區是sp; &nbs醫謝p; &n河腦bsp; &nbs跳數p; --langu司線age &n章好bsp; &n紅兒bsp; &nb匠微sp; --老用output &遠身nbsp; &n話坐bsp; &nbs窗上p; &著間nbsp;-lang
--exclude-launch-settings 師慢 --name  不月;  雜分; &n她黃bsp; 討爸 --type &nb兒嗎sp; 們金 &nbs這了p; 子商 明子-n
--force &nbs學年p; &n那她bsp;  少鐘; --no區在-https &外畫nbsp; &nb報看sp; &nbs習醫p; -?  中花; &nb友什sp; &n校火bsp;  煙鐵; &匠議nbsp;-o
--framework &外工nbsp; 煙紙 &nbs習資p; --n司科o-restore 人相 &n哥城bsp;  一喝;-f  上窗; &謝術nbsp; 微歌 &空離nbsp; &關視nbsp;/?--help &nb近跳sp; &n如窗bsp;  也習; 公物 --no-update-check計離 &nb歌但sp; -h &n動都bsp;  話場; &n務窗bsp; 制女 /h
模闆選項的允許值(選擇模闆參數上(shàng)的選擇值)
❯ dotnet new子不 blazorserver --au讀問th IndividualIndividual &nbs農店p; Individua草這lB2C Mult中跳iOrg &nb中了sp; None &nb電你sp; 從坐 SingleOrg  術美; Wind做市ows
NativeAOT 更新(xīn)
将 NativeAOT 從實驗性 dotnet/runtimel窗有ab 存儲庫中移出 并進入穩定的運行時(shí)庫 dot湖一net/runtime repo,但(dàn嗎愛)尚未在 dotnet SDK 中添加一(yī)流的支持吧少,以使用 NativeAOT 發布項目。金城