Fix dotnet build file.cs with MSBuild logger options - #54172
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates dotnet build so --logger / -l are parsed as recognized CLI options, preventing file-based Program.cs builds from being misclassified as regular MSBuild project inputs when logger options appear before the .cs file.
Changes:
- Added hidden
--logger/-loption handling toBuildCommandDefinition. - Forwarded parsed logger values to MSBuild in normalized
--logger:<value>form. - Added regression tests covering file-based build detection with logger options before
Program.cs.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/Cli/Microsoft.DotNet.Cli.Definitions/Commands/Build/BuildCommandDefinition.cs |
Adds hidden logger option parsing/forwarding for dotnet build. |
test/dotnet.Tests/CommandTests/MSBuild/GivenDotnetBuildInvocation.cs |
Adds regression tests for file-based build detection with logger arguments. |
|
cc: @marcpopMSFT or @dsplaisted if you can help to accept/merge this PR, thank you! |
|
Thanks! I would recommend moving this to CommonOptions and then also adding it to publish, pack, clean, and restore, so it works in those cases too. |
91d694e to
829780f
Compare
Good call! Fixed via 829780f |
829780f to
83c35f9
Compare
|
@dsplaisted will it be possible to merge this PR ? |
|
@xoofx sorry for the delay, there are some merge conflicts and test failures that need to be resolved. |
…ith-logger # Conflicts: # test/dotnet.Tests/CommandTests/MSBuild/GivenDotnetBuildInvocation.cs # test/dotnet.Tests/CommandTests/MSBuild/GivenDotnetCleanInvocation.cs # test/dotnet.Tests/CommandTests/MSBuild/GivenDotnetPackInvocation.cs # test/dotnet.Tests/CommandTests/MSBuild/GivenDotnetPublishInvocation.cs # test/dotnet.Tests/CommandTests/MSBuild/GivenDotnetRestoreInvocation.cs
ced3d60 to
4ece4cf
Compare
|
@dsplaisted the branch has been updated with merge conflicts resolved. |
|
@xoofx Thanks, could you look at the test failures? Looks like there are two of them now. |
|
Latest commit is green, just rebased |
Hello, this PR fixes file-based
dotnet builddetection when MSBuild logger options are passed before the C# file, for example:Previously,
Program.cscould stop being recognized as a file-based app entry point and instead be forwarded to physical MSBuild as a project file. MSBuild would then try to parse the C# file as XML and fail withMSB4025.I assume that this could be backported to
net10.0?Root cause
dotnet builddid not define--logger/-las known CLI options. As a result, logger arguments were handled as unmatched/MSBuild-style tokens during parsing, which interfered with theSlnOrProjectOrFileArgumentvalues used by file-based build detection.Fix
Adds hidden
--logger/-loptions toBuildCommandDefinitionand forwards them to MSBuild as:The option uses
AllowSingleArgPerToken()so forms like the following preserveProgram.csas the single file-based entry-point argument:Tests
Added regression coverage verifying that all logger forms above still produce a
VirtualProjectBuildingCommandand forward--logger:xyzto MSBuild, instead of treatingProgram.csas a project file.