Emit Warning When Using CLI Switches from Auto-Response File Lead to Errors#13675
Emit Warning When Using CLI Switches from Auto-Response File Lead to Errors#13675AlesProkop wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves MSBuild CLI diagnostics by emitting the existing “picked up switches from auto-response file” notice before reporting a command-line switch error, so users can more easily identify when an auto-response file (e.g., Directory.Build.rsp) contributed to the failure.
Changes:
- Print response-file pickup notices when a
CommandLineSwitchExceptionis caught (so the notice appears even when parsing fails early). - Add a unit test covering the “project specified both in
Directory.Build.rspand on the command line” (MSB1008) scenario.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/MSBuild/XMake.cs | Prints response-file notices in the switch-error handler and factors the printing into a helper method. |
| src/MSBuild.UnitTests/XMake_Tests.cs | Adds a regression test verifying the notice is present when a switch error occurs with Directory.Build.rsp. |
| /// </summary> | ||
| private List<string> autoResponseFiles; | ||
|
|
||
| internal IReadOnlyList<string> AutoResponseFiles => autoResponseFiles ?? (IReadOnlyList<string>)Array.Empty<string>(); |
There was a problem hiding this comment.
how is this distinct from IncludedResponseFiles?
There was a problem hiding this comment.
IncludedResponseFiles tracks all parsed .rsp files for duplicate/recursive inclusion detection, including explicit @file.rsp, nested .rsp, and auto-discovered ones. AutoResponseFiles is a narrower subset used to remember only the .rsp files MSBuild found automatically, like MSBuild.rsp or Directory.Build.rsp.
Fixes #3789
Context
Currently, if there is a directory.build.rsp with one project specified and then MSBuild is invoked passing a different project through CLI, MSBuild prints an error message:
MSBUILD : error MSB1008: Only one project can be specified.However, there is no indication what is the second project for the user. In MSBuild, there is a warning already implemented which satisfies this. However, it is not printed early enough for this specific scenario. It would be beneficial if the warning would be printed before the error, so the user knows where is the second project specified
Changes Made
XMake.cs
Added a line which emits this warning before the error so the user is notified. The warning used is the one that is already implemented in the MSBuild.
Some command line switches were read from the auto-response file "MSBuild.rsp". To disable this file, use the "/noautoresponse" switch.Testing
XMake_Tests.cs
Added a unit tests for this scenario.