Classic.Console.Templates 0.2.1

dotnet new install Classic.Console.Templates::0.2.1                
此包包含一个 .NET 模板包,您可以从外壳/命令行调用它。

classic-dotnet-templates

提供不使用顶级声明的 .NET 6+ 项目模板。

使用 dotnet 安装此包将在 Visual Studio 2022 和 dotnet new CLI 命令中使模板可用。

从 NuGet 安装

dotnet new -i Classic.Console.Templates

这是什么?

从 .NET 6 开始,控制台应用程序的项目模板使用名为“全局使用”和“顶级声明”的新特性。

这意味着新的控制台项目的 Program.cs 文件看起来像这样

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

而不是看起来像这样的“经典” Program.cs

using System;

namespace MyProject
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello, World!");
        }
    }
}

如果您希望使用“经典”模板,目前没有此选项。安装此模板包将向 VS2022 添加一个“经典”模板

VS2022 Screenshot

使用此模板将允许您选择要使用的模板功能

VS2022 Screenshot

从 CLI 使用

要从命令行创建一个新项目

dotnet new console-classic

模板功能可以切换

dotnet new console-classic --topLevelProgram=false --nrt=true --implicitUsings=false

可用选项

--nrt: If true, turns on nullable reference types. [defaults to 'true']
--topLevelProgram: If true, auto-generates the top level statements, skipping explicit main methods, class and namespace. [defaults to 'false']
--implicitUsings: If true, auto-imports many common using statements. [defaults to 'false']

卸载

此模板包可以通过以下方式卸载:

dotnet new -u Classic.Console.Templates

  • net6.0

    • 无依赖项。

NuGet 包

该包不被任何 NuGet 包使用。

GitHub 仓库

该包不被任何流行的 GitHub 仓库使用。

版本 下载 最后更新
0.2.1 1,493 10/10/2021
0.2.0 468 10/10/2021
0.1.0 294 10/7/2021