Skip to content

Emit Warning When Using CLI Switches from Auto-Response File Lead to Errors#13675

Open
AlesProkop wants to merge 2 commits into
dotnet:mainfrom
AlesProkop:print-rsp-warning
Open

Emit Warning When Using CLI Switches from Auto-Response File Lead to Errors#13675
AlesProkop wants to merge 2 commits into
dotnet:mainfrom
AlesProkop:print-rsp-warning

Conversation

@AlesProkop
Copy link
Copy Markdown
Member

@AlesProkop AlesProkop commented May 4, 2026

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.

@AlesProkop AlesProkop changed the title [Draft] warning before error Emit Warning When Using CLI Switches from Auto-Response File May 4, 2026
@AlesProkop AlesProkop marked this pull request as ready for review May 4, 2026 10:11
Copilot AI review requested due to automatic review settings May 4, 2026 10:11
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 CommandLineSwitchException is caught (so the notice appears even when parsing fails early).
  • Add a unit test covering the “project specified both in Directory.Build.rsp and 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.

Comment thread src/MSBuild/XMake.cs Outdated
Comment thread src/MSBuild.UnitTests/XMake_Tests.cs
@AlesProkop AlesProkop changed the title Emit Warning When Using CLI Switches from Auto-Response File Emit Warning When Using CLI Switches from Auto-Response File Lead to Errors May 4, 2026
/// </summary>
private List<string> autoResponseFiles;

internal IReadOnlyList<string> AutoResponseFiles => autoResponseFiles ?? (IReadOnlyList<string>)Array.Empty<string>();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how is this distinct from IncludedResponseFiles?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Should print .rsp warning when arguments are invalid

3 participants