Skip to content

Provide non-throwing command-line parsing for unknown switches #15218

Description

@baronfel

Summary

Expose a way to parse MSBuild command-line arguments without throwing when the input includes switches that MSBuild does not recognize. The parser should return the unrecognized arguments (or otherwise make them available to the caller) along with the parsed MSBuild switches.

Microsoft.Build.CommandLine.Experimental.CommandLineParser.Parse(IEnumerable<string>) currently ends in CommandLineSwitches.ThrowErrors(), so an unknown switch raises UnknownSwitchError. Callers that need to distinguish MSBuild options from arguments intended for another process cannot use it for classification, because those non-MSBuild arguments are expected input rather than errors.

This is needed by the .NET SDK as it evaluates using MSBuild's parser to replace hand-maintained switch allowlists; see dotnet/sdk#56123. The parser was extracted for reuse in dotnet/msbuild#12836.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions