点击上蓝字
关注我们
(阅读本文需要15分钟)
今天,我们很高兴发布 .NET 7 预览版 2。.NET 7 的第二个预览版包括 RegEx 源生成器的增强 NativeAOT 从实验状态到运行的进展,以及dotnet new”CLI 一系列重大改进经验。您可以立即获得并开始尝试新功能,例如:
- 在编译过程中使用源生成器,而不是在运行过程中使用较慢的方法来构建特殊的 RegEx 模式匹配发动机。
- dotnet new 利用 SDK 改进为探索模板和参数提供了新的简化选项卡完成体验。
- 尝试使用自己的创新解决方案 NativeAOT。
预览版2
▌ 引入新的正则表达源生成器
新的正则表达源生成器在没有额外成本的情况下,为我们的编译引擎带来了更多的性能优势,它还可以提供出色的调试体验和修剪方便。如果您的模式在编译过程中已知,新的正则表达源生成器可以帮助您。
您只需将包含类型转换为部分类型并使用 RegexGenerator 属性声明了一种新的部分方法,它将返回优化 Regex 对象。源代码生成器将为您填写该方法的实现,并在您更改模式或输入其他选项时自动更新。
更新前
public bool Bar(string input){bool isMatch = regex.IsMatch(input);// ..}}
更新后
publicboolBar( stringinput ) {boolisMatch = MyRegex.IsMatch(input); // <-- Use the generated engine by invoking the partial method.// ..}}
▌SDK 改进
- [Epic] 新的 CLI #2191
对于 7.0.100-preview 2,dotnet new 命令为用户使用的许多子命令提供了一个更一致和直观的界面。此外,对模板选项和参数表符完成的支持已经大量更新,现在用户可以快速反馈有效的参数和选项。
以下是新的帮助输出示例:
Usage:dotnet new[< template- short-name> [< template-args>...]] [options] dotnet new[command] [options]
Arguments:< template- short-name> A shortname of the templateto create. < template-args> Template specific options to use.
Options:-?,-h,--help Show command line help.
Commands:install <package> Installs a templatepackage. uninstall <package> Uninstalls a templatepackage. update Checks the currently installed templatepackages forupdate,andinstall the updates. search < template-name> Searches forthe templates on NuGet.org. list< template-name> Lists templates containing the specified templatename. If no name is specified,lists all templates.
新命令名称
新命令名称
具体来说,这种帮助输出中的所有命令都不再像现在那样具有--前缀。这更符合用户对 CLI 应用程序中子命令的期望。旧版本( --install等)仍然可以用来防止用户脚本的损坏,但我们希望将来在这些命令中添加过时警告来鼓励迁移。
Tab自动补全
Tab自动补全
dotnet CLI 在 PowerShell、bash、zsh 和 fish 等流行的 shell 上支持 tab 补充已经有一段时间了(关于如何使用它的说明,请参考如何使用 .NET CLI 启用 TAB 补充)。然而,有意义的补充取决于单独的实现dotnet命令.NET 7,new 命令学习如何提供 Tab 自动补充。
- 可用模板名称(in dotnet new <template-short-name>)
- ( Web模板中的模板选项列表)
- 这些模板选项的允许值(模板参数的选择值)
当然,也有一些已知的差距——例如,-- language 不建议安装语言值。
- 未来的工作
在未来的预览版本中,我们计划继续填补过渡留下的空白,并自动完成或像用户可以执行的单一命令一样简单。我们希望这将改善整个 dotnet CLI 的 Tab 补充功能,被社区广泛使用!
- 下一步是什么?
dotnet new users – 启用Tab补充并尝试使用模板!模板作者 –尝试在你的模板上Tab补充,并确保您提供您希望用户拥有的体验。提出您在哪里dotnet/templating 仓库中发现的任何问题都有助于我们使 .NET 7 成为 dotnet new 最佳版本!
- NativeAOT 更新
我们之前宣布我们将 NativeAOT项目从实验状态转移到 .NET 7 主线开发。在过去的几个月里,我们一直埋头编码 NativeAOT 从实验性dotnet/runtimelab repo移出并进入dotnet/runtime repo。
这项工作已经完成,但我们还没有 dotnet SDK 添加支持,使用 NativeAOT 发布项目。我们希望尽快完成这项工作,这样您就可以在您的应用程序中尝试 NativeAOT。同时,请尝试修剪您的应用程序,并确保没有修剪警告。修剪是 NativeAOT 要求。如果您有任何库,请参考修剪库的说明。
引入新的正则表达源生成器
https://github.com/dotnet/runtime/issues/44676
[Epic] 新的 CLI #2191
https://github.com/dotnet/templating/issues/2191
如何为 .NET CLI 启用 TAB 补全
https://docs.microsoft.com/dotnet/core/tools/enable-tab-autocomplete
dotnet/templating 存储中的问题解决方案
https://github.com/dotnet/templating/issues/2191
NativeAOT 项目
https://github.com/dotnet/runtime/issues/61231
dotnet/runtimelab repo中移出
https://github.com/dotnet/runtimelab
dotnet/runtime
https://github.com/dotnet/runtimelab
应用
https://docs.microsoft.com/dotnet/core/deploying/trimming/trim-self-contained
准备修剪库的说明
https://docs.microsoft.com/dotnet/core/deploying/trimming/prepare-libraries-for-trimming
引入新的正则表达源生成器
https://github.com/dotnet/runtime/issues/44676
[Epic] 新的 CLI 解析器 选项卡完成 #2191
https://github.com/dotnet/templating/issues/2191
如何为 .NET CLI 启用 TAB 补全
https://docs.microsoft.com/dotnet/core/tools/enable-tab-autocomplete
dotnet/templating 存储中的问题解决方案
https://github.com/dotnet/templating/issues/2191
NativeAOT 项目
https://github.com/dotnet/runtime/issues/61231
dotnet/runtimelab repo中移出
https://github.com/dotnet/runtimelab
dotnet/runtime
https://github.com/dotnet/runtimelab
应用
https://docs.microsoft.com/dotnet/core/deploying/trimming/trim-self-contained
准备修剪库的说明
https://docs.microsoft.com/dotnet/core/deploying/trimming/prepare-libraries-for-trimming
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
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 和 .NET Core 官方支持政策
https://dotnet.microsoft.com/platform/support/policy/dotnet-core
.NET 和 .NET Core 官方支持政策
https://dotnet.microsoft.com/platform/support/policy/dotnet-core
重大变化
通过阅读过阅读 .NET找到 7 中最新的重大变更文档.NET 7 重大变更列表。根据区域和版本列出重大变更,并附有详细说明的链接。
检查提出了哪些重大变更,但仍在审查中,请注意Proposed .NET Breaking Changes GitHub 问题。
- .最新的 .NET https://docs.microsoft.com/dotnet/core/compatibility/7.0
- .Proposed .NET Breaking Changes GitHub 问题 https://github.com/dotnet/core/issues/7131
路线图
.NET 版本包括产品、库、运行时和工具,代表了 Microsoft 内外团队之间的合作。您可以通过阅读产品路线图了解更多关于这些领域的信息:
- ASP.NET Core 7 和 Blazor 路线图 https://github.com/dotnet/aspnetcore/issues/39504
- EF 7 路线图 https://docs.microsoft.com/ef/core/what-is-new/ef-core-7.0/plan
- ML.NET https://github.com/dotnet/machinelearning/blob/main/ROADMAP.md
- .NET MAUI https://github.com/dotnet/maui/wiki/Roadmap
- WinForms https://github.com/dotnet/winforms/blob/main/docs/roadmap.md
- WPF https://github.com/dotnet/wpf/blob/main/roadmap.md
- NuGet https://github.com/NuGet/Home/issues/11571
- Roslyn https://github.com/dotnet/roslyn/blob/main/docs/Language Feature Status.md
- Runtime https://github.com/dotnet/core/blob/main/r oadmap.md
马上使用
EF7 预览版 2 也已发布,可在 NuGet 上使用。也可以读 ASP.NET Core 2 预览版新功能。适用于 可下载Windows、macOS 和 Linux 的.NET 7 预览版 2 。假如你想在 Visual Studio 试用 .NET 7,我们建议您使用预览频道版本。Visual Studio for Mac 对 .NET 7 预览版的支持不可用,但即将推出。
- . 可在 NuGet 上使用 https://www.nuget.org/packages/Microsoft.EntityFrameworkCore/7.0.0-preview.2.22153.1
- ASP.NET Core 2 预览版新功能 https://devblogs.microsoft.com/dotnet/asp-net-core-updates-in-dotnet-7-preview-2/
- .NET 7 预览版 2 https://dotnet.microsoft.com/download/dotnet/7.0
- 安装程序和二进制文件https://dotnet.microsoft.com/download/dotnet/7.0
- 容器图像 https://github.com/dotnet/core/blob/master/release-notes/7.0/
- Linux 软件包 https://github.com/dotnet/core/blob/master/release-notes/7.0/
- 发行说明 https://github.com/dotnet/core/tree/master/release-notes/7.0
- 已知问题 https://github.com/dotnet/core/blob/main/release-notes/7.0/known-issues.md
- GitHub 问题跟踪器 https://github.com/dotnet/core/issues
- 预览频道版https://visualstudio.com/preview
感谢大家对 .NET 所有的支持和贡献。请尝试使用 .NET 7 预览版2 并在留言区告诉我们您的想法!
谢谢你读完这篇文章~我相信你必须有一些想要表达的感受、观点和问题。欢迎在评论区畅所欲言,期待听到你的声音!
同时,别忘了把你喜欢的内容转发给你的朋友。谢谢你的支持!
关注微软中国MSDN
下载.NET 7 预览版2