natemcmaster / CommandLineUtils

Command line parsing and utilities for .NET

Home Page:https://natemcmaster.github.io/CommandLineUtils/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Question] Unrecognized command or argument handling

ko-vasilev opened this issue · comments

Hello,
I'm trying to use this library with WixSharp.
For some reason, the WixSharp needs to pass some custom arguments to the application that I don't need myself. So I see the following error:
Unhandled Exception: McMaster.Extensions.CommandLineUtils.UnrecognizedCommandParsingException: Unrecognized command or argument '/MSBUILD:MyProjectName'

I tried adding SetRemainingArgsPropertyOnModel convention and RemainingArgs property on my model, but that didn't help.

What I end up doing right now is the following:

...

try
{
    return commandLineApplication.Execute(args);
}
catch (CommandParsingException ex)
{
    if (ex.Message.StartsWith("Unrecognized command or argument '/MSBUILD:"))
    {
        // This exception happens when the WIX installer is being setup for the first time
        // Just ignore it.
        return 0;
    }

    throw;
}

But it looks very ugly to me. Is there is a proper way to ignore the extra arguments I'm missing?

Thanks, looks like adding [Command(UnrecognizedArgumentHandling = UnrecognizedArgumentHandling.CollectAndContinue)] in my case was enough.