明天,咱们很快乐公布 .NET 7 预览版 2。.NET 7 的第二个预览版包含对 RegEx 源生成器的加强、将 NativeAOT 从试验状态转移到运行时的停顿,以及对"dotnet new"CLI 的一系列重大改良教训。这些可供您立刻获取_并_开始尝试新性能,例如:
- 在编译时应用源生成器而不是在运行时应用较慢的办法来构建专门的 RegEx 模式匹配引擎。
- dotnet new利用 SDK 改良提供全新的简化选项卡实现体验来摸索模板和参数。
- 不要削减用你本人的翻新解决方案尝试 NativeAOT。
EF7 预览版 2 也已公布,可在NuGet 上应用。您还能够浏览ASP.NET Core Preview 2 中的新增性能。
您能够下载实用于 Windows、macOS 和 Linux 的.NET 7 Preview 2 。
- 安装程序和二进制文件
- 容器图像
- Linux 软件包
- 发行阐明
- 已知的问题
- GitHub 问题跟踪器
如果您想在 Visual Studio 系列产品中试用 .NET 7,咱们建议您应用预览频道版本。Visual Studio for Mac 对 .NET 7 预览版的反对尚不可用,但行将推出。
预览版 2
Preview 2 版本当初提供以下性能。
引入新的正则表达式源生成器
https://github.com/dotnet/runtime/issues/44676
您是否已经心愿领有针对您的特定模式优化的专用正则表达式引擎所带来的所有微小益处,而无需在运行时构建该引擎的开销?
咱们很快乐地发表蕴含在预览版 1 中的新正则表达式源生成器。它带来了咱们编译引擎的所有性能劣势,而无需启动老本,并且它具备其余劣势,例如提供杰出的调试体验以及修剪-敌对的。如果您的模式在编译时是已知的,那么新的正则表达式源生成器就是要走的路。
为了开始应用它,您只须要将蕴含类型转换为局部类型,并应用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 options public static partial Regex MyRegex(); // <-- Declare the partial method, which will be implemented by the source generator public bool Bar(string input) { bool isMatch = MyRegex().IsMatch(input); // <-- Use the generated engine by invoking the partial method. // .. }}
就是这样。请尝试一下,如果您有任何反馈,请通知咱们。
SDK 改良
[[Epic] 新的 CLI 解析器 + 选项卡实现 #2191](https://github.com/dotnet/tem...)
对于7.0.100-preview2 , dotnet new命令为用户曾经应用的许多子命令提供了更加统一和直观的界面。此外,对模板选项和参数的制表符实现的反对已失去大量更新,当初能够在用户键入时对无效参数和选项提供疾速反馈。
以下是新的帮忙输入示例:
❯ dotnet new --helpDescription: 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 补全曾经有一段时间了(无关如何启用它的阐明,请参阅如何为.NET CLI 启用TAB 补全)。然而,实现有意义的补全取决于独自的dotnet命令。对于 .NET 7,new命令学习了如何提供Tab主动补全
- 可用的模板名称(in dotnet new < template-short-name > )
❯ dotnet new angularangular grpc razor viewstart worker -hblazorserver mstest razorclasslib web wpf /? blazorwasm mvc razorcomponent webapi wpfcustomcontrollib /hclasslib nugetconfig react webapp wpflib install console nunit reactredux webconfig wpfusercontrollib listeditorconfig nunit-test sln winforms xunit search gitignore page tool-manifest wnformscontrollib --help uninstall globaljson proto viewimports winformslib -? update
- 模板选项(Web模板中的模板选项列表)
❯ dotnet new web --dry-run--dry-run --language --output -lang--exclude-launch-settings --name --type -n--force --no-https -? -o--framework --no-restore -f /?--help --no-update-check -h /h
- 这些模板选项的允许值(抉择模板参数上的抉择值)
❯ dotnet new blazorserver --auth IndividualIndividual IndividualB2C MultiOrg None SingleOrg Windows
当然也有一些已知的差距——例如,-- language不倡议装置语言值。
将来的工作
在将来的预览版中,咱们打算持续填补这一过渡留下的空白,并让主动实现或像用户能够执行的单个命令一样简略。咱们心愿这将改良整个dotnet CLI 的Tab补全性能,并被社区更宽泛地应用!
下一步是什么
dotnet new users – 启用Tab补全并尝试应用模板!模板作者 – 在您的模板上尝试Tab补全,并确保您提供您心愿您的用户领有的体验。大家 - 提出您在dotnet/templating存储库中发现的任何问题,并帮忙咱们使.NET 7 成为dotnet new的最佳版本!
NativeAOT 更新
咱们之前发表,咱们正在将NativeAOT 我的项目从试验状态转移到 .NET 7 的主线开发中。在过来的几个月里,咱们始终在埋头进行编码,以将 NativeAOT 从实验性dotnet/runtimelab repo中移出并进入dotnet/runtimerepo。
该工作现已实现,但咱们尚未在 dotnet SDK 中增加反对,来应用 NativeAOT 公布我的项目。咱们心愿尽快实现这项工作,以便您能够在您的应用程序中试用 NativeAOT。同时,请尝试修剪您的利用并确保没有修剪正告。修剪是 NativeAOT 的要求。如果您领有任何库,请参考筹备进行修剪库的阐明。
Targeting .NET 7
要targeting .NET 7,您须要在我的项目文件中应用 .NET 7 Target Framework Moniker (TFM)。例如:
<TargetFramework> net7.0 </TargetFramework>
全套 .NET 7 TFM,包含特定于操作系统的TFM。
- net7.0
- net7.0-android
- net7.0-ios
- net7.0-maccatalyst
- net7.0-macos
- net7.0-tvos
- net7.0-windows
咱们心愿从 .NET 6 降级到 .NET 7 应该很简略。请报告您在应用 .NET 7 测试现有应用程序的过程中发现的任何重大更改。
反对
.NET 7 是 以后 版本,这意味着它将在公布之日起 18 个月内取得收费反对和补丁。请务必留神,所有版本的品质都是雷同的。惟一的区别是反对的工夫。无关 .NET 反对政策的更多信息,请参阅.NET 和.NET Core 官网反对政策。
重大变动
您能够通过浏览 .NET 7 中的重大更改文档找到最新的.NET 7 重大更改列表。它按区域和版本列出了重大更改,并附有具体阐明的链接。
要查看提出了哪些重大更改但仍在审核中,请关注Proposed .NET Breaking Changes GitHub 问题。
路线图
.NET 版本包含产品、库、运行时和工具,代表了 Microsoft 内外多个团队之间的合作。您能够通过浏览产品路线图理解无关这些畛域的更多信息:
- ASP.NET Core 7 和Blazor 路线图
- EF 7 路线图
- ML.NET
- .NET MAUI
- WinForms
- WPF
- NuGet
- Roslyn
- Runtime
完结
咱们感谢您对 .NET 的所有反对和奉献。请尝试 .NET 7 Preview 2 并通知咱们您的想法!