如果要将应用从 .NET Framework 迁移到 .NET Core 版本 1.0 到 3.1,本文中列出的重大更改可能会影响你。 重大变更按类别分组,并且在每个类别中按 .NET Core 版本的引入顺序进行分组。
注释
本文不是 .NET Framework 和 .NET Core 之间重大更改的完整列表。 在我们发现最重要的中断性变更时,会将其添加到此处。
核心 .NET 库
- UseShellExecute 的默认值更改
- 已删除 IDispatchImplAttribute API
- FileSystemInfo.Attributes 引发的 UnauthorizedAccessException
- 不支持处理损坏的进程状态异常
- UriBuilder 属性不再前面追加前导字符
- Process.StartInfo 对未启动的进程引发 InvalidOperationException
.NET 8
已删除 IDispatchImplAttribute API
.NET Core 2.1
UseShellExecute 的默认值更改
ProcessStartInfo.UseShellExecute 在 .NET Core 上具有默认值 false
。 在 .NET Framework 上,其默认值为 true
.
更改描述
Process.Start 允许你直接启动应用程序,例如,使用诸如启动 Paint 之类的 Process.Start("mspaint.exe")
代码。 它还允许你间接启动关联的应用程序(如果 ProcessStartInfo.UseShellExecute 设置为 true
)。 在 .NET Framework 上,默认值ProcessStartInfo.UseShellExecute为true
,这意味着,如果您已将Process.Start("mytextfile.txt")
文件与该编辑器关联,则代码将启动记事本。 若要防止在 .NET Framework 上间接启动应用,必须显式将 ProcessStartInfo.UseShellExecute 设置为 false
。 在 .NET Core 上,默认值 ProcessStartInfo.UseShellExecute 为 false
. 这意味着,默认情况下,调用 Process.Start
时不会启动关联的应用程序。
以下System.Diagnostics.ProcessStartInfo上的属性仅在ProcessStartInfo.UseShellExecute为true
时才有效:
- ProcessStartInfo.CreateNoWindow
- ProcessStartInfo.ErrorDialog
- ProcessStartInfo.Verb
- ProcessStartInfo.WindowStyle。
出于性能原因,.NET Core 中引入了此更改。 通常, Process.Start 用于直接启动应用程序。 直接启动应用不需要涉及 Windows shell 并产生相关的性能成本。 为了使此默认情况更快,.NET Core 会将默认值 ProcessStartInfo.UseShellExecute 更改为 false
。 如果需要,可以选择慢速路径。
已引入的版本
2.1
注释
在早期版本的 .NET Core 中, UseShellExecute
未针对 Windows 实现。
建议的措施
如果应用依赖于旧行为,请调用 Process.Start(ProcessStartInfo),并将 UseShellExecute 设置为 true
对象上的 ProcessStartInfo。
类别
核心 .NET 库
受影响的 API
.NET Core 1.0
FileSystemInfo.Attributes 引发的 UnauthorizedAccessException
在 .NET Core 中,当调用方尝试设置文件属性值但不具有写入权限时,将引发一个 UnauthorizedAccessException 。
更改描述
在 .NET Framework 中,当调用方尝试在其中ArgumentException设置文件属性值但不具有写入权限时,将引发此FileSystemInfo.Attributes事件。 在 .NET Core 中,将改为引发 UnauthorizedAccessException。 (在 .NET Core 中,如果调用方尝试设置无效的文件属性, ArgumentException 仍会引发此事件。
已引入的版本
1.0
建议的措施
根据需要修改任何 catch
语句不是捕获 UnauthorizedAccessException,而是捕获或者除它之外还捕获 ArgumentException。
类别
核心 .NET 库
受影响的 API
不支持处理损坏状态异常
不支持在 .NET Core 中处理损坏的进程状态异常。
更改描述
以前,可以通过托管代码异常处理程序捕获和处理损坏的进程状态异常,例如,在 C# 中使用 try-catch 语句。
从 .NET Core 1.0 开始,托管代码无法处理损坏的进程状态异常。 公共语言运行时不会向托管代码提供损坏的进程状态异常。
已引入的版本
1.0
建议的措施
通过解决导致这些异常的情况来避免需要处理损坏进程状态异常。 如果绝对有必要处理损坏的进程状态异常,请在 C 或 C++ 代码中编写异常处理程序。
类别
核心 .NET 库
受影响的 API
- System.Runtime.ExceptionServices.HandleProcessCorruptedStateExceptionsAttribute
- legacyCorruptedStateExceptionsPolicy 元素
UriBuilder 属性不再在前面添加前导字符
UriBuilder.Fragment不再追加前导#
字符,UriBuilder.Query不再在已经存在?
字符的情况下追加前导?
字符。
更改描述
在 .NET Framework 中,UriBuilder.Fragment 和 UriBuilder.Query 属性始终在要存储的值前面分别添加 #
或 ?
字符。 如果字符串已包含其中一个前导字符,则此行为可能会导致存储值中的多个 #
或 ?
字符。 例如,值 UriBuilder.Fragment 可能变为 ##main
。
从 .NET Core 1.0 开始,如果在字符串的开头已经存在一个字符,则这些属性将不再将 #
或 ?
字符预置到存储值之前。
已引入的版本
1.0
建议的措施
设置属性值时,不再需要显式删除这些前导字符中的任何一个。 这在追加值时特别有用,因为不再需要在每次追加时删除前导 #
或 ?
。
例如,以下代码片段显示了 .NET Framework 和 .NET Core 之间的行为差异。
var builder = new UriBuilder();
builder.Query = "one=1";
builder.Query += "&two=2";
builder.Query += "&three=3";
builder.Query += "&four=4";
Console.WriteLine(builder.Query);
- 在 .NET Framework 中,输出为
????one=1&two=2&three=3&four=4
. - 在 .NET Core 中,输出为
?one=1&two=2&three=3&four=4
.
类别
核心 .NET 库
受影响的 API
Process.StartInfo 对未启动的进程引发 InvalidOperationException
对于你的代码未启动的进程,读取其 Process.StartInfo 属性会引发 InvalidOperationException。
更改描述
在 .NET Framework 中,访问 Process.StartInfo 代码未启动的进程的属性将返回虚拟 ProcessStartInfo 对象。 虚拟对象包含其所有属性的默认值,但除外 EnvironmentVariables。
从 .NET Core 1.0 开始,如果你读取一个并非由你启动的进程的 Process.StartInfo 属性(即通过调用 Process.Start),则会抛出一个 InvalidOperationException。
已引入的版本
1.0
建议的措施
不要访问你的代码未启动的进程的 Process.StartInfo 属性。 例如,不要读取由Process.GetProcesses返回的进程的此属性。
类别
核心 .NET 库
受影响的 API
密码学
.NET Core 2.1
在 SignedCms.ComputeSignature 中,布尔参数得到遵守
在 .NET Core 中,silent
方法的布尔SignedCms.ComputeSignature(CmsSigner, Boolean)参数会被遵循。 如果此参数设置为 true
,则不会显示 PIN 提示。
更改描述
在 .NET Framework 中,silent
方法的 SignedCms.ComputeSignature(CmsSigner, Boolean) 参数会被忽略,如果提供程序需要,仍然会始终显示 PIN 提示。 在 .NET Core 中, silent
将遵循该参数,如果设置为 true
该参数,则永远不会显示 PIN 提示,即使提供程序需要该提示。
在 2.1 版的 .NET Core 中引入了对 CMS/PKCS #7 消息的支持。
已引入的版本
2.1
建议的措施
若要确保出现 PIN 提示(如果需要),桌面应用程序应调用 SignedCms.ComputeSignature(CmsSigner, Boolean) 布尔参数并将其设置为 false
。 无论在 .NET Framework 中是否禁用无提示上下文,生成的行为都与 .NET Framework 上的行为相同。
类别
密码学
受影响的 API
MSBuild
.NET Core 3.0
资源清单的文件名更改
从 .NET Core 3.0 开始,在默认情况下,MSBuild 会为资源文件生成不同的清单文件名。
已引入的版本
3.0
更改描述
在 .NET Core 3.0 之前,如果在项目文件中的LogicalName
项未指定ManifestResourceName
、DependentUpon
或EmbeddedResource
元数据,MSBuild 则会按照<RootNamespace>.<ResourceFilePathFromProjectRoot>.resources
模式生成清单文件名。 如果在项目文件中未定义 RootNamespace
,则默认值是项目名称。 例如,根项目目录中名为 Form1.resx 的资源文件生成的清单名称为 MyProject.Form1.resources。
从 .NET Core 3.0 开始,如果资源文件与同名源文件(例如 Form1.resx 和 Form1.cs)并置,MSBuild 将使用源文件中的类型信息在模式 <Namespace>.<ClassName>.resources
中生成清单文件名。 命名空间和类名称是从并置源文件的第一个类型中提取的。 例如,与名为Form1.cs 的源文件并置的名为Form1.resx 的资源文件生成的清单名称为 MyNamespace.Form1.resources。 需要注意的要点是,文件名的第一部分与以前版本的 .NET Core(MyNamespace 而不是 MyProject)不同。
注释
如果指定了LogicalName
、ManifestResourceName
或DependentUpon
元数据在项目文件中的EmbeddedResource
项上,则此更改不会影响该资源文件。
此中断性变更是由于将 EmbeddedResourceUseDependentUponConvention
属性添加到 .NET Core 项目而引入的。 默认情况下,资源文件不会在 .NET Core 项目文件中显式列出,因此没有 DependentUpon
元数据来指定如何命名生成的 .resources 文件。 将EmbeddedResourceUseDependentUponConvention
设置为true
时(默认情况下),MSBuild 会查找同一位置的源文件,并从该文件中提取命名空间和类名。 如果将 EmbeddedResourceUseDependentUponConvention
设置为 false
,MSBuild 会根据之前的行为生成清单名称,该行为将 RootNamespace
与相对文件路径合并。
建议的措施
在大多数情况下,开发人员无需执行任何作,并且你的应用应继续工作。 但是,如果此更改导致应用出现故障,则可以:
将代码更改为需要新的清单名称。
通过将项目文件中的
EmbeddedResourceUseDependentUponConvention
设置为false
来选择退出新的命名约定。<PropertyGroup> <EmbeddedResourceUseDependentUponConvention>false</EmbeddedResourceUseDependentUponConvention> </PropertyGroup>
类别
MSBuild
受影响的 API
无
网络
.NET Core 2.0
WebClient.CancelAsync 并不总是立即取消
从 .NET Core 2.0 开始,如果响应已开始提取,则调用 WebClient.CancelAsync() 不会立即取消请求。
更改描述
以前,调用 WebClient.CancelAsync() 会立即取消请求。 从 .NET Core 2.0 开始,仅当响应尚未开始提取时,调用 WebClient.CancelAsync() 才会立即取消请求。 如果响应已开始提取,则仅在读取完整响应后才会取消请求。
实施此更改是因为 WebClient API 已弃用,并且优先使用 HttpClient。
已引入的版本
2.0
建议的措施
使用System.Net.Http.HttpClient类代替已弃用的System.Net.WebClient类。
类别
网络
受影响的 API
Windows 窗体
已在 .NET Core 的版本 3.0 中添加 Windows 窗体支持。 如果要将 Windows 窗体应用从 .NET Framework 移植到 .NET Core,此处列出的重大更改可能会影响你的应用。
- 已删除的控件
- 如果显示工具提示,则不引发 CellFormatting 事件
- Control.DefaultFont 更改为 Segoe UI 9 pt
- FolderBrowserDialog 的现代化
- SerializableAttribute 属性已从某些 Windows 窗体类型中删除
- 不支持 AllowUpdateChildControlIndexForTabControls 兼容性开关
- 不支持 DomainUpDown.UseLegacyScrolling 兼容性开关
- DoNotLoadLatestRichEditControl 兼容性选项不受支持
- 不支持 DoNotSupportSelectAllShortcutInMultilineTextBox 兼容性开关
- 不支持 DontSupportReentrantFilterMessage 兼容性开关
- 不支持 EnableVisualStyleValidation 兼容性开关
- 不支持 UseLegacyContextMenuStripSourceControlValue 兼容性开关
- UseLegacyImages 兼容性切换不受支持
- Visual Basic 的 About 和 SplashScreen 模板已损坏
- Microsoft.VisualBasic.ApplicationServices 命名空间中的类型不可用
- Microsoft.VisualBasic.Devices 命名空间中的类型不可用
- Microsoft.VisualBasic.MyServices 命名空间中的类型不可用
.NET Core 3.1
已删除的控件
从 .NET Core 3.1 开始,某些 Windows 窗体控件不再可用。
更改描述
从 .NET Core 3.1 开始,各种 Windows 窗体控件不再可用。 .NET Framework 2.0 中引入了具有更好设计和支持的替换控件。 弃用的控件以前已从设计器工具箱中删除,但仍可供使用。
以下类型不再可用:
- ContextMenu
- DataGrid
- DataGrid.HitTestType
- DataGrid.HitTestInfo
- DataGridBoolColumn
- DataGridCell
- DataGridColumnStyle
- DataGridColumnStyle.DataGridColumnHeaderAccessibleObject
- DataGridColumnStyle.CompModSwitches
- DataGridLineStyle
- DataGridParentRowsLabelStyle
- DataGridPreferredColumnWidthTypeConverter
- DataGridTableStyle
- DataGridTextBox
- DataGridTextBoxColumn
- GridColumnStylesCollection
- GridTablesFactory
- GridTableStylesCollection
- IDataGridEditingService
- IMenuEditorService
- MainMenu
- Menu
- Menu.MenuItemCollection
- MenuItem
- ToolBar
- ToolBarAppearance
- ToolBarButton
- ToolBar.ToolBarButtonCollection
- ToolBarButtonClickEventArgs
- ToolBarButtonStyle
- ToolBarTextAlign
已引入的版本
3.1
建议的措施
每个已删除的控件都有建议的替换控件。 请参阅以下表:
已删除的控件 (API) | 建议的替换 | 已删除的关联 API |
---|---|---|
ContextMenu | ContextMenuStrip | |
DataGrid | DataGridView | DataGridCell、DataGridRow、DataGridTableCollection、DataGridColumnCollection、DataGridTableStyle、DataGridColumnStyle、DataGridLineStyle、DataGridParentRowsLabel、DataGridParentRowsLabelStyle、DataGridBoolColumn、DataGridTextBox、GridColumnStylesCollection、GridTableStylesCollection、HitTestType |
主菜单 | MenuStrip | |
菜单 | ToolStripDropDown、ToolStripDropDownMenu | MenuItemCollection |
菜单项 | ToolStripMenuItem | |
工具栏 | ToolStrip | ToolBarAppearance |
工具栏按钮 | 工具条按钮 | ToolBarButtonClickEventArgs、ToolBarButtonClickEventHandler、ToolBarButtonStyle、ToolBarTextAlign |
类别
Windows 窗体
受影响的 API
- System.Windows.Forms.ContextMenu
- System.Windows.Forms.GridColumnStylesCollection
- System.Windows.Forms.GridTablesFactory
- System.Windows.Forms.GridTableStylesCollection
- System.Windows.Forms.IDataGridEditingService
- System.Windows.Forms.MainMenu
- System.Windows.Forms.Menu
- System.Windows.Forms.Menu.MenuItemCollection
- System.Windows.Forms.MenuItem
- System.Windows.Forms.ToolBar
- System.Windows.Forms.ToolBar.ToolBarButtonCollection
- System.Windows.Forms.ToolBarAppearance
- System.Windows.Forms.ToolBarButton
- System.Windows.Forms.ToolBarButtonClickEventArgs
- System.Windows.Forms.ToolBarButtonStyle
- System.Windows.Forms.ToolBarTextAlign
- System.Windows.Forms.DataGrid
- System.Windows.Forms.DataGrid.HitTestType
- System.Windows.Forms.DataGridBoolColumn
- System.Windows.Forms.DataGridCell
- System.Windows.Forms.DataGridColumnStyle
- System.Windows.Forms.DataGridLineStyle
- System.Windows.Forms.DataGridParentRowsLabelStyle
- System.Windows.Forms.DataGridPreferredColumnWidthTypeConverter
- System.Windows.Forms.DataGridTableStyle
- System.Windows.Forms.DataGridTextBox
- System.Windows.Forms.DataGridTextBoxColumn
- System.Windows.Forms.Design.IMenuEditorService
如果显示工具提示,则不引发 CellFormatting 事件
现在,当鼠标悬停和通过键盘选择时,DataGridView 将显示单元格的文本和错误工具提示。 如果显示了工具提示,则不会触发 DataGridView.CellFormatting 事件。
更改描述
在 .NET Core 3.1 之前,当鼠标悬停在单元格上时,如果 DataGridView 属性被设置为 ShowCellToolTips,那么 true
会显示该单元格文本的工具提示和错误信息。 当通过键盘选择单元格时,不会显示工具提示(例如,通过使用 Tab 键、快捷键或箭头导航)。 如果用户编辑了一个单元格,然后,当 DataGridView 仍处于编辑模式时,将鼠标悬停在未 ToolTipText 设置属性的单元格上,则会引发一个 CellFormatting 事件来设置单元格的文本的格式,以便在单元格中显示。
为满足辅助功能标准,自 .NET Core 3.1 起,将 DataGridView 属性设置为 ShowCellToolTips 的 true
不仅在鼠标悬停在单元格上时会显示单元格文本和错误的工具提示,而且在通过键盘选择单元格时也会显示。 由于这一变更,如果鼠标在 CellFormatting 处于编辑模式时悬停在未设置 属性的单元格上,不会引发 ToolTipText 事件DataGridView。 不引发该事件的原因是鼠标悬停的单元格的内容显示为工具提示,而不是显示在单元格中。
已引入的版本
3.1
建议的措施
重构任何依赖于 CellFormatting 事件的代码,而此时 DataGridView 正处于编辑模式。
类别
Windows 窗体
受影响的 API
没有
.NET Core 3.0
默认控件字体更改为 Segoe UI 9 pt
更改描述
在 .NET Framework 中,属性 Control.DefaultFont 设置为 Microsoft Sans Serif 8.25 pt
. 下图显示了使用默认字体的窗口。
从 .NET Core 3.0 开始,默认字体设置为 Segoe UI 9 pt
(与 SystemFonts.MessageBoxFont字体相同)。 由于此更改,窗体和控件的大小约为 27% 大,以考虑新的默认字体的大小。 例如:
此更改旨在与 Windows 用户体验(UX)指南保持一致。
已引入的版本
3.0
建议的措施
由于窗体和控件的大小发生更改,请确保应用程序正确呈现。
若要保留单个窗体的原始字体,请将其默认字体设置为 Microsoft Sans Serif 8.25 pt
。 例如:
public MyForm()
{
InitializeComponent();
Font = new Font(new FontFamily("Microsoft Sans Serif"), 8.25f);
}
或者,可以通过以下任一方式更改整个应用程序的默认字体:
通过将 MSBuild 属性设置为
ApplicationDefaultFont
“Microsoft Sans Serif, 8.25pt”。 这是首选技术,因为它允许 Visual Studio 在设计器中使用新设置。<PropertyGroup> <ApplicationDefaultFont>Microsoft Sans Serif, 8.25pt</ApplicationDefaultFont> </PropertyGroup>
通过调用 Application.SetDefaultFont(Font)。
class Program { [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.SetHighDpiMode(HighDpiMode.SystemAware); Application.SetDefaultFont(new Font(new FontFamily("Microsoft Sans Serif"), 8.25f)); Application.Run(new Form1()); } }
类别
- Windows 窗体
受影响的 API
没有。
FolderBrowserDialog 的现代化
控件 FolderBrowserDialog 在适用于 .NET Core 的 Windows 窗体应用程序中已更改。
更改描述
在 .NET Framework 中,Windows 窗体对 FolderBrowserDialog 控件使用以下对话框:
在 .NET Core 3.0 中,Windows 窗体使用 Windows Vista 中引入的基于 COM 的较新的控件:
已引入的版本
3.0
建议的措施
对话将自动升级。
如果想要保留原始对话,请将 FolderBrowserDialog.AutoUpgradeEnabled 属性设置为 false
显示对话框之前,如以下代码片段所示:
var dialog = new FolderBrowserDialog();
dialog.AutoUpgradeEnabled = false;
dialog.ShowDialog();
类别
Windows 窗体
受影响的 API
已从一些 Windows 窗体类型中删除 SerializableAttribute
某些没有已知二进制序列化方案的 Windows 窗体类中已删除了SerializableAttribute元素。
更改描述
以下类型使用 .NET Framework 进行 SerializableAttribute 修饰,但在 .NET Core 中删除了该属性:
System.InvariantComparer
- System.ComponentModel.Design.ExceptionCollection
- System.ComponentModel.Design.Serialization.CodeDomSerializerException
System.ComponentModel.Design.Serialization.CodeDomComponentSerializationService.CodeDomSerializationStore
- System.Drawing.Design.ToolboxItem
System.Resources.ResXNullRef
System.Resources.ResXDataNode
System.Resources.ResXFileRef
- System.Windows.Forms.Cursor
System.Windows.Forms.NativeMethods.MSOCRINFOSTRUCT
System.Windows.Forms.NativeMethods.MSG
从历史上看,这种序列化机制存在严重的维护和安全问题。 保证类型上持续具有 SerializableAttribute
意味着必须针对版本间的序列化更改以及可能出现的框架间序列化更改测试这些类型。 这使得发展这些类型变得更加困难,并且维护成本高昂。 这些类型没有已知的二进制序列化方案,可最大程度地减少删除属性的影响。
有关详细信息,请参阅 二进制序列化。
已引入的版本
3.0
建议的措施
对于要标记为“可序列化”的类型,更新可能依赖它们的所有代码。
类别
Windows 窗体
受影响的 API
- 没有
不支持 AllowUpdateChildControlIndexForTabControls 兼容性开关
Switch.System.Windows.Forms.AllowUpdateChildControlIndexForTabControls
兼容性开关在 .NET Framework 4.6 及更高版本上的 Windows 窗体中受支持,但在自 .NET Core 或 .NET 5.0 及更高版本中不受支持。
更改描述
在 .NET Framework 4.6 及更高版本中,选择选项卡对其控件集合进行重新排序。 兼容性 Switch.System.Windows.Forms.AllowUpdateChildControlIndexForTabControls
开关允许应用程序在不需要此行为时跳过此重新排序。
在 .NET Core 和 .NET 5.0 及更高版本中, Switch.System.Windows.Forms.AllowUpdateChildControlIndexForTabControls
不支持该开关。
已引入的版本
3.0
建议的措施
删除开关。 不支持该开关,并且没有可用的替代功能。
类别
Windows 窗体
受影响的 API
- 没有
不支持 DomainUpDown.UseLegacyScrolling 兼容性开关
Switch.System.Windows.Forms.DomainUpDown.UseLegacyScrolling
兼容性开关是在 .NET Framework 4.7.1 中引入的,但不在 .NET Core 或 .NET 5.0 及更高版本的 Windows 窗体中受支持。
更改描述
从 .NET Framework 4.7.1 开始,Switch.System.Windows.Forms.DomainUpDown.UseLegacyScrolling
兼容性开关允许开发人员选择不参与独立 DomainUpDown.DownButton() 和 DomainUpDown.UpButton() 操作。 该开关会还原旧行为,也就是说如果存在上下文文本,则忽略 DomainUpDown.UpButton()而且开发人员需要先在控件上执行 DomainUpDown.DownButton() 操作,然后才能执行 DomainUpDown.UpButton() 操作。 有关详细信息,请参阅 <AppContextSwitchOverrides> 元素。
在 .NET Core 和 .NET 5.0 及更高版本中, Switch.System.Windows.Forms.DomainUpDown.UseLegacyScrolling
不支持该开关。
已引入的版本
3.0
建议的措施
删除开关。 不支持该开关,并且没有可用的替代功能。
类别
Windows 窗体
受影响的 API
不支持 DoNotLoadLatestRichEditControl 兼容性开关
Switch.System.Windows.Forms.UseLegacyImages
兼容性开关是在 .NET Framework 4.7.1 中引入的,但不在 .NET Core 或 .NET 5.0 及更高版本的 Windows 窗体中受支持。
更改描述
在 .NET Framework 4.6.2 和以前的版本中,控件 RichTextBox 实例化 Win32 RichEdit 控件 v3.0,对于面向 .NET Framework 4.7.1 的应用程序, RichTextBox 该控件实例化 RichEdit v4.1( msftedit.dll)。
Switch.System.Windows.Forms.DoNotLoadLatestRichEditControl
引入了兼容性开关,允许面向 .NET Framework 4.7.1 及更高版本的应用程序选择退出新的 RichEdit v4.1 控件,并改用旧的 RichEdit v3 控件。
在 .NET Core 和 .NET 5.0 及更高版本中, Switch.System.Windows.Forms.DoNotLoadLatestRichEditControl
不支持该开关。 仅支持新版本的 RichTextBox 控件。
已引入的版本
3.0
建议的措施
删除开关。 不支持该开关,并且没有可用的替代功能。
类别
Windows 窗体
受影响的 API
不支持 DoNotSupportSelectAllShortcutInMultilineTextBox 兼容性开关
Switch.System.Windows.Forms.DoNotSupportSelectAllShortcutInMultilineTextBox
.NET Framework 4.6.1 中引入的兼容性开关在 .NET Core 和 .NET 5.0 及更高版本的 Windows 窗体中不受支持。
更改描述
从 .NET Framework 4.6.1 开始,在控制中按下 + TextBox快捷键会选择所有文本。 在 .NET Framework 4.6 和以前的版本中,如果 Textbox.ShortcutsEnabled 和 + 属性都设置为 ,则选择 CtrlTextBox.Multilinetrue
快捷键无法选择所有文本。
Switch.System.Windows.Forms.DoNotSupportSelectAllShortcutInMultilineTextBox
.NET Framework 4.6.1 中引入了兼容性开关,以保留原始行为。 有关详细信息,请参阅 TextBox.ProcessCmdKey。
在 .NET Core 和 .NET 5.0 及更高版本中, Switch.System.Windows.Forms.DoNotSupportSelectAllShortcutInMultilineTextBox
不支持该开关。
已引入的版本
3.0
建议的措施
删除开关。 不支持该开关,并且没有可用的替代功能。
类别
Windows 窗体
受影响的 API
- 没有
不支持 DontSupportReentrantFilterMessage 兼容性开关
Switch.System.Windows.Forms.DontSupportReentrantFilterMessage
.NET Framework 4.6.1 中引入的兼容性开关在 .NET Core 和 .NET 5.0 及更高版本的 Windows 窗体中不受支持。
更改描述
从 .NET Framework 4.6.1 开始,Switch.System.Windows.Forms.DontSupportReentrantFilterMessage
兼容性开关解决了当使用自定义IndexOutOfRangeException实现调用Application.FilterMessage消息时可能出现的IMessageFilter.PreFilterMessage异常。 有关详细信息,请参阅缓解:自定义 IMessageFilter.PreFilterMessage 实现。
在 .NET Core 和 .NET 5.0 及更高版本中, Switch.System.Windows.Forms.DontSupportReentrantFilterMessage
不支持该开关。
已引入的版本
3.0
建议的措施
删除开关。 不支持该开关,并且没有可用的替代功能。
类别
Windows 窗体
受影响的 API
不支持 EnableVisualStyleValidation 兼容性开关
.NET Core 或 .NET 5.0 及更高版本上的 Windows 窗体不支持 Switch.System.Windows.Forms.EnableVisualStyleValidation
兼容性开关。
更改描述
在 .NET Framework 中,Switch.System.Windows.Forms.EnableVisualStyleValidation
兼容性开关允许应用程序选择不验证以数字形式提供的视觉样式。
在 .NET Core 和 .NET 5.0 及更高版本中, Switch.System.Windows.Forms.EnableVisualStyleValidation
不支持该开关。
已引入的版本
3.0
建议的措施
删除开关。 不支持该开关,并且没有可用的替代功能。
类别
Windows 窗体
受影响的 API
- 没有
不支持 UseLegacyContextMenuStripSourceControlValue 兼容性开关
已在 .NET Framework 4.7.2 中引入 Switch.System.Windows.Forms.UseLegacyContextMenuStripSourceControlValue
兼容性开关,但它在 .NET Core 或 .NET 5.0 及更高版本上的 Windows 窗体中尚不受支持。
更改描述
Switch.System.Windows.Forms.UseLegacyContextMenuStripSourceControlValue
兼容性开关允许开发人员选择退出 ContextMenuStrip.SourceControl 属性的新行为。从 .NET Framework 4.7.2 开始,该属性现在返回对源代码控制的引用。 属性的先前行为是返回 null
。 有关详细信息,请参阅 <AppContextSwitchOverrides> 元素。
在 .NET Core 和 .NET 5.0 及更高版本中, Switch.System.Windows.Forms.UseLegacyContextMenuStripSourceControlValue
不支持该开关。
已引入的版本
3.0
建议的措施
删除开关。 不支持该开关,并且没有可用的替代功能。
类别
Windows 窗体
受影响的 API
不支持 UseLegacyImages 兼容性开关
Switch.System.Windows.Forms.UseLegacyImages
兼容性开关在 .NET Framework 4.8 中被引入,但在 .NET Core 或 .NET 5.0 及更高版本的 Windows 窗体中不受支持。
更改描述
从 .NET Framework 4.8 开始, Switch.System.Windows.Forms.UseLegacyImages
兼容性开关解决了高 DPI 环境中的 ClickOnce 方案中可能出现的图像缩放问题。 将开关设置为true
时,该开关允许用户在DPI设置超过100%时还原旧图像缩放。 有关详细信息,请参阅 GitHub 上的 .NET Framework 4.8 发行说明 。
在 .NET Core 和 .NET 5.0 及更高版本中, Switch.System.Windows.Forms.UseLegacyImages
不支持该开关。
已引入的版本
3.0
建议的措施
删除开关。 不支持该开关,并且没有可用的替代功能。
类别
Windows 窗体
受影响的 API
- 没有
“关于”和“初始屏幕”模板已断开
由 Visual Studio 生成的 About.vb
和 SplashScreen.vb
文件包含对 My
命名空间中不可用的类型(.NET Core 3.0 和 3.1)。
已引入的版本
3.0
更改描述
.NET Core 3.0 和 3.1 不包含完整的 Visual Basic My
支持。 Visual Studio for Visual Basic Windows 窗体应用中的“关于”和“初始屏幕”窗体模板引用 My.Application.Info
类型中不可用的属性。
建议的措施
.NET 5 中改进了 Visual Basic My
支持,将项目升级到 .NET 5 或更高版本。
-或-
修复应用中 About 和 SplashScreen 类型中的编译器问题。 使用 System.Reflection.Assembly
类获取 My.Application.Info
类型提供的信息。 此处提供了两种窗体的直端口。
小窍门
这是示例代码和未优化的代码。 应缓存属性列表以减少表单加载时间。
关于
Imports System.Reflection
Public NotInheritable Class About
Private Sub about_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Set the title of the form.
Dim applicationTitle As String = Assembly.GetExecutingAssembly().GetCustomAttribute(Of AssemblyTitleAttribute)()?.Title
If String.IsNullOrEmpty(applicationTitle) Then
applicationTitle = System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().GetName().Name)
End If
Me.Text = String.Format("About {0}", applicationTitle)
' Initialize all of the text displayed on the About Box.
' TODO: Customize the application's assembly information in the "Application" pane of the project
' properties dialog (under the "Project" menu).
Me.LabelProductName.Text = If(Assembly.GetExecutingAssembly().GetCustomAttribute(Of AssemblyProductAttribute)()?.Product, "")
Me.LabelVersion.Text = String.Format("Version {0}", Assembly.GetExecutingAssembly().GetName().Version)
Me.LabelCopyright.Text = If(Assembly.GetExecutingAssembly().GetCustomAttribute(Of AssemblyCopyrightAttribute)()?.Copyright, "")
Me.LabelCompanyName.Text = If(Assembly.GetExecutingAssembly().GetCustomAttribute(Of AssemblyCompanyAttribute)()?.Company, "")
Me.TextBoxDescription.Text = If(Assembly.GetExecutingAssembly().GetCustomAttribute(Of AssemblyDescriptionAttribute)()?.Description, "")
End Sub
Private Sub OKButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OKButton.Click
Me.Close()
End Sub
End Class
SplashScreen
Imports System.Reflection
Public NotInheritable Class SplashScreen
Private Sub SplashScreen1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Set up the dialog text at runtime according to the application's assembly information.
'TODO: Customize the application's assembly information in the "Application" pane of the project
' properties dialog (under the "Project" menu).
'Application title
Dim appTitle As String = Assembly.GetExecutingAssembly().GetCustomAttribute(Of AssemblyTitleAttribute)()?.Title
If String.IsNullOrEmpty(appTitle) Then
appTitle = System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().GetName().Name)
End If
ApplicationTitle.Text = appTitle
Dim versionValue = Assembly.GetExecutingAssembly().GetName().Version
'Format the version information using the text set into the Version control at design time as the
' formatting string. This allows for effective localization if desired.
' Build and revision information could be included by using the following code and changing the
' Version control's designtime text to "Version {0}.{1:00}.{2}.{3}" or something similar. See
' String.Format() in Help for more information.
'
' Version.Text = System.String.Format(Version.Text, versionValue.Major, versionValue.Minor, versionValue.Build, versionValue.Revision)
Version.Text = System.String.Format(Version.Text, versionValue.Major, versionValue.Minor)
'Copyright info
Copyright.Text = If(Assembly.GetExecutingAssembly().GetCustomAttribute(Of AssemblyCopyrightAttribute)()?.Copyright, "")
End Sub
End Class
类别
Visual Basic Windows 窗体
受影响的 API
没有
Microsoft.VisualBasic.ApplicationServices 命名空间中的类型不可用
命名空间中的 Microsoft.VisualBasic.ApplicationServices 类型不可用。
已引入的版本
.NET Core 3.0
更改描述
命名空间中的 Microsoft.VisualBasic.ApplicationServices 类型在 .NET Framework 中可用。 它们在 .NET Core 3.0 - 3.1 中不可用。
已删除这些类型,以避免在后续版本中出现不必要的程序集依赖项或中断性变更。
建议的措施
此命名空间已添加到 .NET 5 中,将项目升级到 .NET 5 或更高版本。
-或-
如果代码依赖于类型及其成员的使用 Microsoft.VisualBasic.ApplicationServices ,则可以在 .NET 类库中使用相应的类型或成员。 例如,某些 System.Environment 成员和 System.Security.Principal.WindowsIdentity 成员提供与类属性 Microsoft.VisualBasic.ApplicationServices.User 等效的功能。
类别
Visual Basic
受影响的 API
Microsoft.VisualBasic.Devices 命名空间中的类型不可用
命名空间中的 Microsoft.VisualBasic.Devices 类型不可用。
已引入的版本
.NET Core 3.0
更改描述
命名空间中的 Microsoft.VisualBasic.Devices 类型在 .NET Framework 中可用。 它们在 .NET Core 3.0 - 3.1 中不可用。
已删除这些类型,以避免在后续版本中出现不必要的程序集依赖项或中断性变更。
建议的措施
此命名空间已添加到 .NET 5 中,将项目升级到 .NET 5 或更高版本。
-或-
如果代码依赖于类型及其成员的使用 Microsoft.VisualBasic.Devices ,则可以在 .NET 类库中使用相应的类型或成员。 例如,类型 Microsoft.VisualBasic.Devices.Clock 和 System.DateTime 提供与类 System.Environment 相同的功能,命名空间中的 Microsoft.VisualBasic.Devices.Ports 类型提供与类 System.IO.Ports 相同的功能。
类别
Visual Basic
受影响的 API
Microsoft.VisualBasic.MyServices 命名空间中的类型不可用
命名空间中的 Microsoft.VisualBasic.MyServices 类型不可用。
已引入的版本
.NET Core 3.0
更改描述
命名空间中的 Microsoft.VisualBasic.MyServices 类型在 .NET Framework 中可用。 它们在 .NET Core 3.0 - 3.1 中不可用。
已删除这些类型,以避免在后续版本中出现不必要的程序集依赖项或中断性变更。
建议的措施
此命名空间已添加到 .NET 5 中,将项目升级到 .NET 5 或更高版本。
-或-
如果代码取决于 Microsoft.VisualBasic.MyServices 类型及其成员的使用,则 .NET 类库中有相应的类型和成员。 下面是 Microsoft.VisualBasic.MyServices 类型与其等效的 .NET 类库类型的映射:
Microsoft.VisualBasic.MyServices 类型 | .NET 类库类型 |
---|---|
ClipboardProxy | System.Windows.Clipboard 适用于 WPF 应用程序,System.Windows.Forms.Clipboard 适用于 Windows 窗体应用程序 |
FileSystemProxy | 命名空间中的 System.IO 类型 |
RegistryProxy | 命名空间 Microsoft.Win32 中与注册表相关的类型 |
SpecialDirectoriesProxy | Environment.GetFolderPath |
类别
Visual Basic