Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Using System.CommandLine with custom Main() signature

I’m trying to use System.CommandLine and I’ve installed the nuget package:

Install-Package System.CommandLine -Version 2.0.0-beta1.21308.1

According to this Microsoft article, I should be able to just write a Main() method with my signature and it should auto-magically work:

static void Main(FileInfo input, FileInfo output)
{
    Console.WriteLine($"Hello World! {input} {output}");
}

However my Main() method signature is rejected and I get CS5001: Program does not contain a static 'Main' method suitable for an entry point.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Am I doing something wrong? According to the article, this is how System.CommandLine should be working.

>Solution :

Make sure to target .NET 5.0, and run these 2 commands in the Package Manager Console:

Install-Package System.CommandLine -Version 2.0.0-beta1.21308.1
Install-Package System.CommandLine.DragonFruit -Version 0.3.0-alpha.21216.1 

After that it should work.


Explanation: In order to use System.CommandLine, you also need to install a NuGet package called DragonFruit.

It’s this package that enables the custom command line parameters.

See here for details: https://github.com/dotnet/command-line-api/blob/main/docs/DragonFruit-overview.md

Also note that you also need C# version 9 or later to support Top-Level Statements, but you have confirmed that you’re using that – I mention it here for other readers.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading