Repository navigation
File-based apps: recognize more logger arguments - #54637
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes file-based app argument handling so MSBuild logger-related switches (notably terminal logger args like -tl:off) no longer prevent file-based app detection for dotnet build/clean/publish/run, and improves the fallback warnings by surfacing which arguments caused fallback to MSBuild.
Changes:
- Added logger-argument separation (
-tl*,-tlp*,-clp*,--terminalLogger*,--consoleLoggerParameters*, plus existing binlog args) and used it in file-based app routing. - Enhanced file-based fallback warnings to include the unsupported/unrecognized arguments list, and updated localization resources accordingly.
- Added/updated tests covering logger-argument forms and warning output expectations.
Reviewed changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| test/dotnet.Tests/LoggerUtilityTests.cs | New unit tests for recognizing/normalizing logger argument forms. |
| test/dotnet.Tests/CommandTests/Run/RunFileTests_General.cs | Adds coverage for duplicate file-path args in run and updates warning assertions to include unsupported arg lists. |
| test/dotnet.Tests/CommandTests/Run/RunFileTests_BuildOptions.cs | Adds end-to-end tests ensuring logger args don’t break file-based run/build paths and are not forwarded to the app. |
| src/Cli/dotnet/LoggerUtility.cs | Introduces generalized logger-argument recognition and separation (beyond binlog). |
| src/Cli/dotnet/Commands/Run/RunCommand.cs | Uses the new logger-argument separation when building msbuild-forwarded args for dotnet run. |
| src/Cli/dotnet/Commands/CommandFactory.cs | Uses logger-argument separation for file-based app detection and enriches fallback warnings with arg lists. |
| src/Cli/dotnet/Commands/CliCommandStrings.resx | Updates warning strings to include unsupported/unrecognized arguments. |
| src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hant.xlf | Localization update for modified warning strings. |
| src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hans.xlf | Localization update for modified warning strings. |
| src/Cli/dotnet/Commands/xlf/CliCommandStrings.tr.xlf | Localization update for modified warning strings. |
| src/Cli/dotnet/Commands/xlf/CliCommandStrings.ru.xlf | Localization update for modified warning strings. |
| src/Cli/dotnet/Commands/xlf/CliCommandStrings.pt-BR.xlf | Localization update for modified warning strings. |
| src/Cli/dotnet/Commands/xlf/CliCommandStrings.pl.xlf | Localization update for modified warning strings. |
| src/Cli/dotnet/Commands/xlf/CliCommandStrings.ko.xlf | Localization update for modified warning strings. |
| src/Cli/dotnet/Commands/xlf/CliCommandStrings.ja.xlf | Localization update for modified warning strings. |
| src/Cli/dotnet/Commands/xlf/CliCommandStrings.it.xlf | Localization update for modified warning strings. |
| src/Cli/dotnet/Commands/xlf/CliCommandStrings.fr.xlf | Localization update for modified warning strings. |
| src/Cli/dotnet/Commands/xlf/CliCommandStrings.es.xlf | Localization update for modified warning strings. |
| src/Cli/dotnet/Commands/xlf/CliCommandStrings.de.xlf | Localization update for modified warning strings. |
| src/Cli/dotnet/Commands/xlf/CliCommandStrings.cs.xlf | Localization update for modified warning strings. |
|
@333fred @RikkiGibson for reviews, thanks |
| out List<string> loggerArgs, | ||
| out List<string> nonLoggerArgs) |
There was a problem hiding this comment.
Do these really need to be lists? Can they be IA?
| new FileInfo(binaryLogPath).Should().NotExist(); | ||
| } | ||
|
|
||
| [Theory] |
|
@RikkiGibson for a second review |
| if (!TryCountApplicationArgumentsBeforeDoubleDash(applicationArguments, applicationArgumentsAfterDoubleDash, out var countBeforeDoubleDash)) | ||
| { | ||
| // This hopefully should not happen, but if it does, we don't want to break users. | ||
| Reporter.Error.WriteLine("Warning: Could not determine which application arguments appeared after '--'. All application arguments will be passed to the application without treating logger arguments specially.".Yellow()); |
There was a problem hiding this comment.
The fallback warning in SeparateApplicationLoggerArguments is an inline English literal written to Reporter.Error, bypassing CliCommandStrings.resx/.xlf. Non-English users would get an untranslated message.
There was a problem hiding this comment.
Yes, but this is more like an assert, it should not happen as far as I'm aware (on the other hand I'm not 100% confident of it, and it could break if System.CommandLine changes behavior, so it felt safer to have a warning + fallback). So I can move it to resx anyway.
| Debug.Assert(nonLoggerArgs[0] == "-"); | ||
| nonLoggerArgs = nonLoggerArgs.SetItem(0, entryPointFilePath); |
There was a problem hiding this comment.
nonLoggerArgs = nonLoggerArgs.SetItem(0, entryPointFilePath); is never read again. The command passes the separate args array to applicationArgs, and args already had - stripped and the temp path is passed separately via entryPointFileFullPath. Drop line 922, keep the Debug.Assert invariant.
There was a problem hiding this comment.
Good catch, thanks, looks like that was a pre-existing issue with nonBinLogArgs too.
Fixes #51809.
Fixes #54715.
First commit also improves the error message for unknown args (see #54540 (comment)).
cc @baronfel