默认情况下禁用 .NET 6 功能

Disabling .NET 6 features per default

使用 .NET 6 在 VS 2022 中创建新项目时,会自动添加以下新功能:

有没有办法创建 .NET 6 项目

一个。可空引用类型 - 保留它们

我建议保留可空引用类型。我会回应 Embracing nullable reference types 并说所有新代码都应该使用它。这是原始声明:

When .NET 5 rolls around, if we feel the nullable rollout phase has been a success, I could see us turning the feature on by default for new projects in Visual Studio. If the ecosystem is ready for it, there is no reason why any new code should ignore the improved safety and reliability you get from nullability annotations!

乙。顶级语句

2022 年 5 月更新

VS2022 17.3.0(预览版 1.1)支持在创建控制台应用程序时禁用 top-level 语句:


原创

针对.net5框架并编辑项目文件是使用旧程序风格的官方方式

请参阅Use the old program style

While a .NET 6 console app template generates the new style of top-level statements programs, using .NET 5 doesn't. By creating a .NET 5 project, you'll receive the old program style. Then, you can edit the project file to target .NET 6 but retain the old program style for the Program.cs file.

The features that make the new program simpler are top-level statements, global using directives, and implicit using directives.

顺便说一句。直接在gihub给官方Should the console project template use top-level statements投票: