我正在尝试使用 System.CommandLine
并且我已经安装了 nuget 包:
Install-Package System.CommandLine -Version 2.0.0-beta1.21308.1
根据 this Microsoft article ,我应该能够用我的签名编写一个 Main() 方法,它应该自动神奇地工作:
static void Main(FileInfo input, FileInfo output)
{
Console.WriteLine($"Hello World! {input} {output}");
}
但是我的 Main() 方法签名被拒绝,我得到 CS5001: Program does not contain a static 'Main' method suitable for an entry point
。
我做错了什么吗?根据这篇文章,这就是 System.CommandLine
应该如何工作。
最佳答案
确保以 .NET 5.0 为目标,并在包管理器控制台中运行这两个命令:
Install-Package System.CommandLine -Version 2.0.0-beta1.21308.1
Install-Package System.CommandLine.DragonFruit -Version 0.3.0-alpha.21216.1
之后它应该可以工作了。
说明:为了使用System.CommandLine
,您还需要安装一个名为 DragonFruit
的 NuGet 包.
正是这个包启用了自定义命令行参数。
详情请看这里:https://github.com/dotnet/command-line-api/blob/main/docs/DragonFruit-overview.md
另请注意,您还需要 C# 版本 9 或更高版本才能支持 Top-Level Statements
,但您已确认您正在使用它 - 我在这里为其他读者提及它。
关于c# - 使用具有自定义 Main() 签名的 System.CommandLine,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70181552/