Skip to content

[fix] Fix LoggerRunSettings verbosity being silently overridden when using --settings#16044

Open
nohwnd wants to merge 2 commits into
mainfrom
fix/issue-10369-8a2bbfcf1b265926
Open

[fix] Fix LoggerRunSettings verbosity being silently overridden when using --settings#16044
nohwnd wants to merge 2 commits into
mainfrom
fix/issue-10369-8a2bbfcf1b265926

Conversation

@nohwnd
Copy link
Copy Markdown
Member

@nohwnd nohwnd commented May 19, 2026

Summary

🤖 This is an automated fix generated by the Issue Triage agent.

Fixes #10369

Root Cause

When running dotnet test --settings my.runsettings with <Verbosity>normal</Verbosity> inside <LoggerRunSettings>, the verbosity is silently overridden and always set to minimal.

Two cooperating issues:

1. TestTaskUtils.CreateCommandLineArguments always injects verbosity

Even when a settings file is provided, the MSBuild VSTest task auto-injects --logger:Console;Verbosity=minimal (or whatever MSBuild-derived verbosity applies). This happens regardless of whether the user configured the console logger in their settings file.

2. LoggerUtilities.AddLoggerToRunSettings discards existing Configuration

When processing the injected --logger:Console;Verbosity=minimal, AddLoggerToRunSettings finds the existing console logger in the LoggerRunSettings (from the .runsettings file), removes it, and replaces it with the newly-constructed one — losing the user's <Verbosity>normal</Verbosity> configuration.

Fix

Part 1 — TestTaskUtils.cs

When isRunSettingsEnabled = true (a settings file is in use), omit Verbosity=X from the auto-injected logger argument. The settings file is the authoritative source for the logger configuration.

Part 2 — LoggerUtilities.cs

In AddLoggerToRunSettings: when the incoming logger has no Configuration (i.e. no CLI parameters were supplied for it) but the existing logger in runsettings does have a Configuration, preserve the existing Configuration rather than discarding it.

Tests

  • TestTaskUtils unit tests: CreateArgumentShouldNotInjectVerbosityWhenSettingsFileIsProvided and CreateArgumentShouldInjectVerbosityWhenNoSettingsFileIsProvided
  • EnableLoggersArgumentProcessor unit tests: ExecutorInitializeShouldPreserveExistingConfigurationWhenNoNewParametersAreProvided and ExecutorInitializeShouldOverrideExistingConfigurationWhenNewParametersAreProvided

Behavior Change

  • Before: dotnet test --settings my.runsettings with <Verbosity>normal</Verbosity> would always show minimal test output regardless of the settings file.
  • After: The verbosity from the settings file is respected.

🔍 Triaged by Issue Repro Triage & Auto-Fix 🔍

…task

When dotnet test is run with --settings <runsettings>, the MSBuild VSTest
task always injected --logger:Console;Verbosity=X. This caused
AddLoggerToRunSettings to remove the existing console logger entry (from
LoggerRunSettings in the settings file) and replace it with one carrying
only the MSBuild-derived verbosity — discarding the user's configured
verbosity.

Root cause: two cooperating issues.

1. TestTaskUtils.CreateCommandLineArguments always included Verbosity=X
   in the auto-injected --logger arg even when a settings file was in use.

2. LoggerUtilities.AddLoggerToRunSettings unconditionally removed and
   replaced an existing logger, losing its Configuration when the new
   logger had no Configuration of its own.

Fix:
- When isRunSettingsEnabled=true (settings file provided), omit Verbosity
  from the auto-injected logger arg so the settings file can supply it.
- In AddLoggerToRunSettings, when the incoming logger has no Configuration
  (no CLI params) but an existing logger does, preserve the existing
  Configuration rather than discarding it.

Fixes #10369

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 19, 2026 01:48
@nohwnd nohwnd added the bug label May 19, 2026
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 fixes an interaction between the MSBuild VSTest task and LoggerRunSettings where dotnet test --settings ... could silently override a console logger’s configured verbosity (e.g., forcing minimal even when the runsettings specified normal). It does so by (1) stopping MSBuild from injecting Verbosity=... when a settings file is used, and (2) preserving existing logger <Configuration> when a logger is re-added without new parameters.

Changes:

  • Update MSBuild task argument construction to omit Verbosity=... on the auto-injected --logger: when --settings is provided.
  • Update LoggerUtilities.AddLoggerToRunSettings to preserve an existing logger’s <Configuration> when the incoming logger has no configuration.
  • Add unit tests covering both the MSBuild argument behavior and the runsettings merge behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/Microsoft.TestPlatform.Build/Tasks/TestTaskUtils.cs Avoid injecting console logger verbosity when a runsettings file is in use.
src/vstest.console/Processors/Utilities/LoggerUtilities.cs Preserve existing logger configuration when re-adding a logger without CLI parameters.
test/Microsoft.TestPlatform.Build.UnitTests/TestTaskUtilsTests.cs Tests for verbosity injection behavior with/without --settings.
test/vstest.console.UnitTests/Processors/EnableLoggersArgumentProcessorTests.cs Tests ensuring configuration is preserved/overridden appropriately when enabling loggers.

Copy link
Copy Markdown
Member Author

@nohwnd nohwnd left a comment

Choose a reason for hiding this comment

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

Review: RunSettings Logger Verbosity Fix

The two-part fix is logically sound and well-targeted at the reported bug. Tests cover the primary scenarios clearly.

One finding worth discussing (see inline):

The isRunSettingsEnabled guard in TestTaskUtils.cs applies to both VSTestTask (Console logger) and VSTestTask2 (MSBuildLogger). For the Console logger this is the intended fix; for MSBuildLogger it silently drops the MSBuild-derived verbosity when a settings file is in use and the file doesn't configure that logger — which is the common case. This may be acceptable by design, but it's worth a conscious decision and an explicit test.

No issues found in:

  • LoggerUtilities.cs — the Configuration preservation is correct. The check logger.Configuration is null && existingLogger.Configuration is not null is precisely scoped. It also applies to explicit --logger:console CLI invocations (not just the MSBuild task path), which is consistent and desirable.
  • Null safety, public API surface, IPC, or cross-TFM concerns — none present.

🧠 Reviewed by Expert Code Reviewer

🧠 Reviewed by Expert Code Reviewer 🧠

vsTestVerbosity = "normal";
}
else if (quietTestLogging.Contains(taskVsTestVerbosity))
builder.AppendSwitchUnquotedIfNotNull("--logger:", loggerToUse);
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.

[Backward Compatibility — VSTestTask2]

The isRunSettingsEnabled branch applies to both VSTestTask (Console logger) and VSTestTask2 (MSBuildLogger). For VSTestTask2 + settings file, the MSBuild-derived verbosity is now silently dropped:

  • Before: --logger:Microsoft.TestPlatform.MSBuildLogger;Verbosity=minimal (or the MSBuild-mapped value)
  • After: --logger:Microsoft.TestPlatform.MSBuildLogger (no verbosity — falls back to the logger's internal default)

If the settings file doesn't contain a <Logger> entry for Microsoft.TestPlatform.MSBuildLogger (the common case), the MSBuildLogger will ignore the MSBuild-derived verbosity entirely. This is a silent behavior change for anyone using VSTestTask2 (i.e., dotnet test via the MSBuild tooling task) with a .runsettings file.

The fix for the Console logger (the bug's subject) is correct; consider whether VSTestTask2 should be treated the same way or whether it needs to retain the MSBuild verbosity pass-through when no settings-file configuration is present for it. A test covering VSTestTask2 + settings file would make the intent explicit.

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.

Good catch. The fix now scopes the verbosity-suppression to task is VSTestTask only. VSTestTask2 (MSBuildLogger) always injects the MSBuild-derived verbosity regardless of whether a settings file is present, since MSBuildLogger verbosity is driven by MSBuild rather than user settings. A test covering VSTestTask2 + settings file is also added to make the intent explicit.

🔧 Iterated by PR Iteration Agent 🔧

…k2 always injects MSBuild-derived verbosity

The 'don't inject Verbosity when settings file is present' fix was
applied to both VSTestTask (Console logger) and VSTestTask2 (MSBuildLogger).
For VSTestTask2, the MSBuildLogger verbosity is driven by MSBuild, not
the user's settings file, so it must always receive the MSBuild-derived
verbosity. Scope the suppression to task is VSTestTask only.

Also adds a test explicitly covering VSTestTask2 + settings file.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@nohwnd
Copy link
Copy Markdown
Member Author

nohwnd commented May 19, 2026

Commit pushed: 7930a74

🔧 Iterated by PR Iteration Agent 🔧

Copy link
Copy Markdown
Member Author

@nohwnd nohwnd left a comment

Choose a reason for hiding this comment

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

Review: LoggerRunSettings Verbosity Fix — Updated

The previous finding (VSTestTask2 verbosity silently dropped when a settings file is present) has been addressed in the follow-up commit. The task is VSTestTask type guard correctly scopes the "no verbosity injection" path to the Console logger only — VSTestTask2 (MSBuildLogger) continues to inject the MSBuild-derived verbosity regardless of whether a settings file is present, which is the intended semantics.

Full analysis of the two-part fix:

Part 1 — TestTaskUtils.cs: The branching logic is correct. When isRunSettingsEnabled && task is VSTestTask, only --logger:Console is injected (no verbosity), deferring to the .runsettings configuration. The else path (VSTestTask2 or no settings file) preserves the original verbosity-injection behavior. The three new tests cover all cases: VSTestTask with settings, VSTestTask without settings, VSTestTask2 with settings.

Part 2 — LoggerUtilities.cs: The logger.Configuration is null && existingLogger.Configuration is not null guard is precisely scoped. It correctly preserves .runsettings Configuration when no new parameters are supplied (whether from the MSBuild task path or from a plain --logger:console CLI invocation), and lets explicit CLI parameters like --logger:console;verbosity=quiet override as before. Null safety is sound — the existingLoggerIndex >= 0 guard makes the array access safe.

Description alignment: Accurate. Both root causes and both fix components are described correctly. The test names in the description match the actual test names.

No issues found.


🧠 Reviewed by Expert Code Reviewer 🧠

🧠 Reviewed by Expert Code Reviewer 🧠

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LoggerRunSettings not working to set verbosity

2 participants