Repository navigation
Conversation
Support IReadOnlyList tokens, unknown-switch collection, unexpanded response-file arguments, and token-only parsing while preserving CLI defaults. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: da6ccb4c-52f9-4389-a389-914271a74a6d
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The preserved enumerable overload can now enumerate list-backed input twice, regressing its prior one-pass behavior.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Adds configurable MSBuild command-line parsing for SDK token classification.
Changes:
- Adds per-call controls for unknown switches, response files, and environment logging arguments.
- Returns unrecognized and unexpanded tokens while preserving order and quoting.
- Adds regression tests and API documentation.
| File | Description |
|---|---|
src/MSBuild/MSBuild.csproj |
Includes the new options source. |
src/MSBuild/CommandLine/CommandLineSwitchesAccessor.cs |
Exposes unrecognized and unexpanded tokens. |
src/MSBuild/CommandLine/CommandLineParsingOptions.cs |
Defines parsing controls. |
src/MSBuild/CommandLine/CommandLineParser.cs |
Implements per-call parsing behavior. |
src/MSBuild.UnitTests/CommandLineParserTests.cs |
Covers options, errors, and parser reuse. |
documentation/specs/command-line-parsing.md |
Documents the experimental API. |
Snapshot enumerable inputs even when they implement IReadOnlyList, add regression coverage, and document the list overload's stable-input contract. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: da6ccb4c-52f9-4389-a389-914271a74a6d
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Related issue(s):
Fixes #15218
Fixes #15219
Related SDK integration: dotnet/sdk#56123
Context
The .NET SDK needs to distinguish MSBuild switches from application arguments without failing on unknown switches or reading response files. The existing experimental parser always throws for unknown switches and gathers response-file and environment inputs.
Changes Made
Add
Parse(IReadOnlyList<string>, CommandLineParsingOptions)to the internal experimental API. Options control unknown-switch exceptions, response-file reading, and inclusion ofMSBUILD_LOGGING_ARGS.When unknown-switch exceptions are disabled, return the original tokens in
UnrecognizedArguments. When response-file reading is disabled, return explicit@filetokens separately inUnexpandedResponseFileArguments. Both collections preserve quoting, order, and duplicates. Options apply to one call and do not affect later calls or earlier results.Add regression coverage and document the API in
documentation/specs/command-line-parsing.md.Compatibility
All options default to the existing behavior. Preserve the
IEnumerable<string>overload and the existing accessor constructor. The CLI continues strict parsing with unchanged response-file handling. Other errors, including malformed known switches, duplicate project arguments, and unreadable or repeated response files, still throw. No new diagnostics or ChangeWave are required because the behavior changes are opt-in. The API remains internal and available to the SDK through the existing friend assembly.Testing
Commands ran on Windows with the repository-local SDK/runtime configured:
.\build.cmd -v quiet /bl:7.binlog— passed, zero warnings and errors..\.dotnet\dotnet.exe test --project "$PWD\src\MSBuild.UnitTests\Microsoft.Build.CommandLine.UnitTests.csproj" --no-restore /bl:5.binlog -- --no-progress— passed on both target frameworks: 1,460 passed, 16 existing platform/issue skips, zero failures..\.dotnet\dotnet.exe test --project "$PWD\src\MSBuild.UnitTests\Microsoft.Build.CommandLine.UnitTests.csproj" --no-build --no-restore /bl:9.binlog -- --filter-class "Microsoft.Build.CommandLine.UnitTests.CommandLineParserTests" --no-progress— final parser regressions passed: 38 cases across both frameworks, no skips.dotnet --versionin the bootstrap environment — returned11.0.100-rc.1.26420.103.dotnet build src\Samples\Dependency\Dependency.csproj -v:q /bl:8.binlogin the bootstrap environment — passed, zero warnings and errors.dotnet msbuild -helpin the bootstrap environment — passed.git --no-pager diff --check— passed.Linux/macOS and the full repository test suite were not run. Initial validation encountered local runtime resolution and bootstrap compiler-lock issues; those were resolved before the successful runs above.
Dependencies and Follow-up
The SDK can adopt these options for token classification in dotnet/sdk#56123 after this API is available. No companion PR is required to merge this change.