.NET Core 3.1 的新增功能What's new in .NET Core 3.1

本文介绍了 .NET Core 3.1 中的新增功能。This article describes what is new in .NET Core 3.1. 此版本包含对 .NET Core 3.0 的细微改进,重点介绍小型但重要的修复。This release contains minor improvements to .NET Core 3.0, focusing on small, but important, fixes. .NET Core 3.1 中最重要的特性为,它是长期支持 (LTS) 版本。The most important feature about .NET Core 3.1 is that it's a long-term support (LTS) release.

如果使用的是 Visual Studio 2019,则必须更新到 Visual Studio 2019 版本 16.4 或更高版本才能使用 .NET Core 3.1 项目。If you're using Visual Studio 2019, you must update to Visual Studio 2019 version 16.4 or later to work with .NET Core 3.1 projects. 有关 Visual Studio 版本 16.4 中新增功能的详细信息,请参阅 Visual Studio 2019 版本 16.4 中的新增功能For information on what's new in Visual Studio version 16.4, see What's New in Visual Studio 2019 version 16.4.

Visual Studio for Mac 也支持 .NET Core 3.1,并且 Visual Studio for Mac 8.4 中就包括 .NET Core 3.1。Visual Studio for Mac also supports and includes .NET Core 3.1 in Visual Studio for Mac 8.4.

有关版本的详细信息,请参阅 .NET Core 3.1 公告For more information about the release, see the .NET Core 3.1 announcement.

长期支持Long-term support

.NET Core 3.1 是未来三年包含来自 Microsoft 的支持的 LTS 版本。.NET Core 3.1 is an LTS release with support from Microsoft for the next three years. 强烈建议将应用移到 .NET Core 3.1。It's highly recommended that you move your apps to .NET Core 3.1. 其他主要版本的当前生命周期如下所示:The current lifecycle of other major releases is as follows:

ReleaseRelease 说明Note
.NET Core 3.0.NET Core 3.0 生命周期终结于 2020 年 3 月 3 日。End of life on March 3, 2020.
.NET Core 2.2.NET Core 2.2 生命周期终结于 2019 年 12 月 23 日。End of life on December 23, 2019.
.NET Core 2.1.NET Core 2.1 生命周期终结于 2021 年 8 月 21 日。End of life on August 21, 2021.

有关详细信息,请参阅 .NET Core 支持策略For more information, see the .NET Core support policy.

macOS appHost 和公证macOS appHost and notarization

仅 macOS macOS only

从已公证的适用于 macOS 的 .NET Core SDK 3.1 开始,默认已禁用 appHost 设置。Starting with the notarized .NET Core SDK 3.1 for macOS, the appHost setting is disabled by default. 有关详细信息,请参阅 macOS Catalina 公证以及对 .NET Core 下载和项目的影响For more information, see macOS Catalina Notarization and the impact on .NET Core downloads and projects.

启用 appHost 设置后,.NET Core 在生成或发布时将生成本机 Mach-O 可执行文件。When the appHost setting is enabled, .NET Core generates a native Mach-O executable when you build or publish. 如果使用 dotnet run 命令从源代码中运行应用,或通过启动 Mach-O 可执行文件直接运行应用,则应用会在 appHost 的上下文中运行。Your app runs in the context of the appHost when it is run from source code with the dotnet run command, or by starting the Mach-O executable directly.

如果没有 appHost,用户就只能使用 dotnet <filename.dll> 命令启动依赖于运行时的应用。Without the appHost, the only way a user can start a runtime-dependent app is with the dotnet <filename.dll> command. 发布独立应用时,始终会创建 appHost。An appHost is always created when you publish your app self-contained.

可以在项目级别配置 appHost,或通过 -p:UseAppHost 参数切换特定 dotnet 命令的 appHost:You can either configure the appHost at the project level, or toggle the appHost for a specific dotnet command with the -p:UseAppHost parameter:

  • 项目文件Project file

    <PropertyGroup>
      <UseAppHost>true</UseAppHost>
    </PropertyGroup>
    
  • 命令行参数Command-line parameter

    dotnet run -p:UseAppHost=true
    

有关 UseAppHost 设置的详细信息,请参阅 Microsoft.NET.Sdk 的 MSBuild 属性For more information about the UseAppHost setting, see MSBuild properties for Microsoft.NET.Sdk.

Windows 窗体Windows Forms

仅限 WindowsWindows only

警告

Windows 窗体中发生重大变更。There are breaking changes in Windows Forms.

旧版控件包含在 Windows 窗体中,这些窗体在一段时间内无法在 Visual Studio 设计器工具箱中使用。Legacy controls were included in Windows Forms that have been unavailable in the Visual Studio Designer Toolbox for some time. 它们已替换为 .NET Framework 2.0 中的新控件。These were replaced with new controls back in .NET Framework 2.0. 它们已从适用于 .NET Core 3.1 的桌面 SDK 中删除。These have been removed from the Desktop SDK for .NET Core 3.1.

已删除的控件Removed control 推荐的替换控件Recommended replacement 已删除关联的 APIAssociated APIs removed
DataGridDataGrid DataGridView DataGridCellDataGridCell
DataGridRowDataGridRow
DataGridTableCollectionDataGridTableCollection
DataGridColumnCollectionDataGridColumnCollection
DataGridTableStyleDataGridTableStyle
DataGridColumnStyleDataGridColumnStyle
DataGridLineStyleDataGridLineStyle
DataGridParentRowsLabelDataGridParentRowsLabel
DataGridParentRowsLabelStyleDataGridParentRowsLabelStyle
DataGridBoolColumnDataGridBoolColumn
DataGridTextBoxDataGridTextBox
GridColumnStylesCollectionGridColumnStylesCollection
GridTableStylesCollectionGridTableStylesCollection
HitTestTypeHitTestType
ToolBarToolBar ToolStrip ToolBarAppearanceToolBarAppearance
ToolBarButtonToolBarButton ToolStripButton ToolBarButtonClickEventArgsToolBarButtonClickEventArgs
ToolBarButtonClickEventHandlerToolBarButtonClickEventHandler
ToolBarButtonStyleToolBarButtonStyle
ToolBarTextAlignToolBarTextAlign
ContextMenuContextMenu ContextMenuStrip
Menu ToolStripDropDown
ToolStripDropDownMenu
MenuItemCollectionMenuItemCollection
MainMenuMainMenu MenuStrip
MenuItemMenuItem ToolStripMenuItem

我们建议你将应用程序更新到 .NET Core 3.1 并移动到替换控件。We recommend you update your applications to .NET Core 3.1 and move to the replacement controls. 替换控件是一个简单的过程,本质上属于“查找和替换”类型。Replacing the controls is a straightforward process, essentially "find and replace" on the type.

C++/CLIC++/CLI

仅限 WindowsWindows only

已添加对创建 C++/CLI(也称为“托管 C++”)项目的支持。Support has been added for creating C++/CLI (also known as "managed C++") projects. 从这些项目生成的二进制文件与 .NET Core 3.0 及更高版本兼容。Binaries produced from these projects are compatible with .NET Core 3.0 and later versions.

若要添加对 Visual Studio 2019 版本 16.4 中的 C++/CLI 的支持,请安装“使用 C++ 的桌面开发”工作负荷To add support for C++/CLI in Visual Studio 2019 version 16.4, install the Desktop development with C++ workload. 此工作负载将两个模板添加到 Visual Studio:This workload adds two templates to Visual Studio:

  • CLR 类库(.NET Core)CLR Class Library (.NET Core)
  • CLR 空项目(.NET Core)CLR Empty Project (.NET Core)

后续步骤Next steps