new|正式发布 | .NET 7 预览版 2

点击上方蓝字
关注我们
(本文阅读所需15分钟)
今天 , 我们很高兴发布 .NET 7 预览版 2 。 .NET 7 的第二个预览版包括对 RegEx 源生成器的增强、将 NativeAOT 从实验状态转移到运行时的进展 , 以及对“dotnet new”CLI 的一系列重大改进经验 。 这些可供您立即获取并开始尝试新功能 , 例如:

  • 在编译时使用源生成器而不是在运行时使用较慢的方法来构建专门的 RegEx 模式匹配引擎 。
  • dotnet new 利用 SDK 改进提供全新的简化选项卡完成体验来探索模板和参数 。
  • 用你自己的创新解决方案尝试 NativeAOT 。
预览版2
▌ 引入新的正则表达式源生成器
新正则表达式源生成器带来了我们编译引擎的更多性能优势 , 而无需额外成本 , 它还可以提供出色的调试体验以及便于修剪 。 如果您的模式在编译时是已知的 , 那么新的正则表达式源生成器可以很好地帮到您 。
您只需要将包含类型转换为部分类型 , 并使用 RegexGenerator 属性声明一个新的部分方法 , 该方法将返回优化的 Regex 对象 。 源代码生成器将为您填充该方法的实现 , 并在您更改模式或传入的其他选项时自动更新 。
更新前
public class Foo { public Regex regex = new Regex(@"abc|def", RegexOptions.IgnoreCase); public bool Bar(string input){bool isMatch = regex.IsMatch(input);// ..}}
更新后
publicpartialclassFoo// <-- Make the class a partial class{[ RegexGenerator(@ "abc|def", RegexOptions.IgnoreCase) ] // <-- Add the RegexGenerator attribute and pass in your pattern and optionspublicstaticpartialRegex MyRegex( ) ; // <-- Declare the partial method, which will be implemented by the source generatorpublicboolBar( 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 命令为用户已经使用的许多子命令提供了更加一致和直观的界面 。 此外 , 对模板选项和参数的制表符完成的支持已得到大量更新 , 现在可以在用户键入时对有效参数和选项提供快速反馈 。
以下是新的帮助输出示例:
? dotnet new--help Deion:Template Instantiation Commands for.NET CLI. 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.
【new|正式发布 | .NET 7 预览版 2】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自动补全
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/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
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 和 .NET Core 官方支持政策
    https://dotnet.microsoft.com/platform/support/policy/dotnet-core
重大变化
您可以通过阅读 .NET 7 中的重大更改文档找到最新的 .NET 7 重大更改列表 。 它按区域和版本列出了重大更改 , 并附有详细说明的链接 。
要查看提出了哪些重大更改但仍在审核中 , 请关注Proposed .NET Breaking Changes GitHub 问题 。
  • .最新的 .NET 7 重大更改列表 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%20Feature%20Status.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

    推荐阅读