如何使用 .net 5.0 通过命令行在现有项目中创建新的 .cs 文件

How to create a new .cs file in an existing project through the command line using .net 5.0

我正在使用 .net 核心通过命令行创建和 运行 一些非常简单的 C# 代码。我使用 dotnet new console 创建了一个新的控制台应用程序。它以我所在目录的名称创建一个 .csproj 文件 ()。所以我有一个 文件夹,其中包含一个 classes.csproj 文件,一个 Program.cs 文件和一些其他文件夹。

为了创建一些 类,我需要一些其他的 .cs 文件,但我不知道如何做。我已经根据 https://docs.microsoft.com/en-us/dotnet/csharp/tutorials/intro-to-csharp/introduction-to-classes 尝试了 File:New 命令,但我一定是使用了错误的语法,因为它说:

The filename, directory name, or volume label syntax is incorrect.

由于我对命令行和编码还很陌生(很明显),我已经在 google 上搜索了一些 cmd 语法,但仍然找不到任何东西来让它工作。

我知道这可以在 Visual Studio 中轻松完成,但我想知道是否有办法使用 cmd 来完成。

遗憾的是,在 dotnet cli 中没有创建 C# 文件的命令行

但是如果你想用终端创建一个 C# 文件,你可以使用下面的命令

在 Linux bash 或 git bash 在 windows

touch YourFileName.cs

在Windows命令中

type NUL > YourFileName.cs