简体   繁体   English

删除 Visual Studio 2022 中默认的 C# 控制台应用程序模板代码

[英]Removing the default c# console application template code in visual studio 2022

When creating a console application project for .net 6.0 c# in visual studio, it generates the following code:在 Visual Studio 中为 .net 6.0 c# 创建控制台应用程序项目时,它会生成以下代码:

// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");

As opposed to previous c# versions, where the project template created some useful boilerplate, non of this is helpful whatsoever.与以前的 c# 版本相反,项目模板创建了一些有用的样板文件,但这些都没有任何帮助。

Is it possible to configure visual studio 2022 so that when creating console applications for c# in .net 6.0 the file will be completely empty?是否可以配置 Visual Studio 2022,以便在 .net 6.0 中为 c# 创建控制台应用程序时,文件将完全为空?

Apparently, when creating a new solution, one has to select the "Do not use top-level statements" checkbox when selecting the .Net version, on the last step of the solution creation.显然,在创建新解决方案时,必须在解决方案创建的最后一步选择 .Net 版本时选中“不使用顶级语句”复选框。 Not exactly by default, but at least there is that option.不完全是默认设置,但至少有这个选项。

From the official docs: create .NET 5 project and then change framework to .NET 6 via editing project file来自官方文档:创建 .NET 5 项目,然后通过编辑项目文件将框架更改为 .NET 6

https://docs.microsoft.com/nl-nl/dotnet/core/tutorials/top-level-templates#use-the-old-program-style https://docs.microsoft.com/nl-nl/dotnet/core/tutorials/top-level-templates#use-the-old-program-style

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
-   <TargetFramework>net5.0</TargetFramework>
+   <TargetFramework>net6.0</TargetFramework>
  </PropertyGroup>

</Project>

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
+   <ImplicitUsings>enable</ImplicitUsings>
+   <Nullable>enable</Nullable>
  </PropertyGroup>

</Project>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM