dotnet / dotnet/command-line-api
First argument is treated as command if it matches the assembly name
- Dominant language
- C#
- Stars
- 3.7k
- Forks
- 428
- PR merge metrics
- No merged PRs in 30d
Description
I have a really weird issue, and it took me a while to understand what was going on.
My project is named `build.csproj`, so its assembly name is "build" (since I didn't explicitly change it). I have defined a "catch all" argument like this:
```csharp
var otherArgs = new Argument("otherArgs", () => [], "Other arguments");
rootCommand.AddArgument(otherArgs);
```
If I call my program with `build` as the first argument on the command line, it's ignored. It took me a long time to understand that it was because it matched the name of the root command (which is apparently set to the assembly name by default), so it was treated as a command, not an argument. So I thought, fine, I'll just change the name of the root command:
```csharp
var rootCommand = new RootCommand { Name = "blah" };
```
And... it didn't change anything. But now `blah` is also ignored if I pass it as the first command line arg. So apparently, if it matches either the root command name _or_ the assembly name, it's treated as the root command.
Why can I even specify the root command? I don't see any use case for this.
How can I get around this, short of renaming the assembly? (which I can do in this case, but it might not always be practical). I need to be able to pass `build` as the first argument and have it treated as an argument, not a command.
Contributor guide
Assessment
This issue has not been assessed yet.