首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >官宣 .NET 7 Preview 2

官宣 .NET 7 Preview 2

作者头像
郑子铭
发布2022-04-19 08:37:28
7840
发布2022-04-19 08:37:28
举报

今天,我们很高兴发布 .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 。

  • 安装程序和二进制文件 https://dotnet.microsoft.com/download/dotnet/7.0
  • 容器图像 https://hub.docker.com/_/microsoft-dotnet
  • 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

如果您想在 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 Preview 2 中的新增功能

https://devblogs.microsoft.com/dotnet/asp-net-core-updates-in-dotnet-7-preview-2/

.NET 7 Preview 2

https://dotnet.microsoft.com/download/dotnet/7.0

预览频道版本

https://visualstudio.com/preview

预览版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/templating/issues/2191

对于7.0.100-preview2dotnet new命令为用户已经使用的许多子命令提供了更加一致和直观的界面。此外,对模板选项和参数的制表符完成的支持已得到大量更新,现在可以在用户键入时对有效参数和选项提供快速反馈。

以下是新的帮助输出示例:

❯ 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 应用程序中子命令的期望。旧版本( --install等)仍可用于防止破坏用户脚本,但我们希望将来在这些命令中添加过时警告以鼓励迁移。

Tab自动补全

dotnet CLI 在 PowerShell、bash、zsh 和 fish 等流行的 shell 上支持 tab 补全已经有一段时间了(有关如何启用它的说明,请参阅如何为 .NET CLI 启用 TAB 补全)。然而,实现有意义的补全取决于单独的dotnet命令。对于 .NET 7,new命令学习了如何提供Tab自动补全

  • 可用的模板名称(in dotnet new)
❯ dotnet new angular
angular              grpc            razor            viewstart       worker               -h
blazorserver         mstest              razorclasslib        web                  wpf         /?      
blazorwasm           mvc    razorcomponent       webapi               wpfcustomcontrollib  /h
classlib             nugetconfig         react         webapp           wpflib     install          
console              nunit      reactredux           webconfig      wpfusercontrollib    list
editorconfig         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 Individual
Individual     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 的要求。如果您拥有任何库,请参考准备进行修剪库的说明。

如何为 .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 官方支持政策。

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 Feature Status.md
  • Runtime https://github.com/dotnet/core/blob/main/roadmap.md

结束

我们感谢您对 .NET 的所有支持和贡献。请尝试 .NET 7 Preview 2 并告诉我们您的想法!

https://dotnet.microsoft.com/thanks

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2022-03-20,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 DotNet NB 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
容器服务
腾讯云容器服务(Tencent Kubernetes Engine, TKE)基于原生 kubernetes 提供以容器为核心的、高度可扩展的高性能容器管理服务,覆盖 Serverless、边缘计算、分布式云等多种业务部署场景,业内首创单个集群兼容多种计算节点的容器资源管理模式。同时产品作为云原生 Finops 领先布道者,主导开源项目Crane,全面助力客户实现资源优化、成本控制。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档