Skip to content

Remove interactive special case for logger verbosity in dotnet run #47389

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 13, 2025

Conversation

baronfel
Copy link
Member

@baronfel baronfel commented Mar 8, 2025

This lights up Terminal Logger support in dotnet run again, using the new factory function.

This also changes the verbosity override in anticipation of MSBuild identifying and always printing auth messages.

My initial version of this applied the verbosity by splatting it as an argument along with the other loose MSBuildArgs. This was hard to track. So I've also added Verbosity tracking to MSBuildArgs so we can set it with less string-munging. Here's the before-and-after of that change:
image

The first dotnet run I wasn't able to set quiet easily, so minimal kept getting applied, overwriting my quiet setting.
The second dotnet run is after I was able to track the Verbosity setting for MSBuild, and ensure we only sent one. The Building... is because this project did opt into building messages in its launchsettings.json.

@ghost ghost added Area-CLI untriaged Request triage from a team member labels Mar 8, 2025
baronfel added a commit to dotnet/msbuild that referenced this pull request Jul 10, 2025
Part of dotnet/sdk#47602

### Context

With `NuGetInteractive=true` being passed in more scenarios as of
dotnet/sdk#47226, the default verbosity for
`dotnet run` is now `minimal` for user-present scenarios - that's gross.

### Changes Made

Broadly what I'm trying to do here is not require passing `-v m` to
loggers to get the authentication-related messages. Right now `dotnet
run` does this and it's quite noisy compared to previous behavior. This
changed because recently I made the SDK start passing `--interactive`
when the user is at the keyboard (similar logic to Terminal Logger's own
enablement), and `dotnet run` has logic to force verbosity to minimal
when that happens so that the auth messages print where a user can see
them.
 
I kind of think of auth messages as messages that we should write
regardless of verbosity (like errors are), so this is a step down that
path for TL.

This change ensures that auth messages are always written in the TL
experience, as immediate messages.

If this is accepted, then the SDK could remove the [special case it
currently has](dotnet/sdk#47389).

### Testing

Updated snapshot baselines, manual testing.

### Notes
@baronfel baronfel closed this Jul 10, 2025
@baronfel baronfel force-pushed the remove-interactive-special-case branch from b47469f to 301f9e9 Compare July 10, 2025 17:41
@baronfel baronfel changed the title Remove interactive special case Remove interactive special case for logger verbosity in dotnet run Jul 10, 2025
@baronfel baronfel reopened this Jul 10, 2025
@baronfel baronfel marked this pull request as ready for review July 11, 2025 01:06
@Copilot Copilot AI review requested due to automatic review settings July 11, 2025 01:06
Copy link
Contributor

@Copilot 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 centralizes verbosity handling by moving VerbosityOptions into the Cli.Utils library, extending MSBuildArgs to carry verbosity state, and simplifying the dotnet run logger setup to use a single factory function.

  • Add Verbosity property and related clone methods to MSBuildArgs and update AnalyzeMSBuildArguments to capture it.
  • Remove ad-hoc interactive verbosity logic in RunCommand, replacing it with SetupSilentBuildArgs and a unified MakeTerminalLogger call.
  • Update all command parsers and tests to use the new Utils.VerbosityOptions and propagate the verbosity option through AnalyzeMSBuildArguments.

Reviewed Changes

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

Show a summary per file
File or Group Description
test/dotnet.Tests/CommandTests/Tool/Update/UpdateToolParserTests.cs (and similar *ParserTests.cs files) Swapped result.GetValue<T> calls for GetRequiredValue where appropriate.
test/dotnet.Tests/CommandTests/MSBuild/GivenDotnetRunInvocation.cs Added RunCommandParser.VerbosityOption to the AnalyzeMSBuildArguments call.
test/Microsoft.DotNet.Tools.Tests.ComponentMocks/ToolPackageDownloaderMock2.cs Updated overrides to use fully-qualified Cli.Utils.VerbosityOptions.
test/Microsoft.DotNet.PackageInstall.Tests/…ToolPackageInstallerNugetCacheTests.cs Added using Microsoft.DotNet.Cli.Utils; for new verbosity enum.
src/Cli/dotnet/CommonOptions.cs & CommonOptionsExtensions.cs Removed inline VerbosityOptions enum and updated imports to Utils.
src/Cli/Microsoft.DotNet.Cli.Utils/VerbosityOptions.cs & MSBuildArgs.cs & MSBuildForwardingAppWithoutLogging.cs Introduced VerbosityOptions enum, added verbosity support to MSBuildArgs, and emitted --verbosity in forwarding.
src/Cli/dotnet/Commands/** Updated all parsers and commands to use Utils.VerbosityOptions and pass the verbosity option to AnalyzeMSBuildArguments.
Comments suppressed due to low confidence (3)

src/Cli/dotnet/Commands/Run/RunCommand.cs:415

  • [nitpick] The variable name thing is unclear—consider renaming it to something more descriptive like terminalLogger or logger.
        var thing = TerminalLogger.CreateTerminalOrConsoleLogger([$"--verbosity:{msbuildVerbosity}", ..buildArgs.OtherMSBuildArgs]);

src/Cli/dotnet/Commands/Run/RunCommand.cs:316

  • [nitpick] Consider adding unit tests to verify that dotnet run correctly includes the --verbosity flag in MSBuildArgs for both default and explicit verbosity levels, ensuring SetupSilentBuildArgs and MakeTerminalLogger behave as intended.
    private MSBuildArgs SetupSilentBuildArgs(MSBuildArgs msbuildArgs)

test/Microsoft.DotNet.Tools.Tests.ComponentMocks/ToolPackageDownloaderMock2.cs:59

  • The namespace qualifier Cli.Utils.VerbosityOptions may not resolve correctly; ensure you either add using Microsoft.DotNet.Cli.Utils; or fully qualify it as Microsoft.DotNet.Cli.Utils.VerbosityOptions.
        protected override void CreateAssetFile(PackageId packageId, NuGetVersion version, DirectoryPath packagesRootPath, string assetFilePath, string runtimeJsonGraph, Cli.Utils.VerbosityOptions verbosity, string? targetFramework = null)

Comment on lines +12 to +20
quiet,
q,
minimal,
m,
normal,
n,
detailed,
d,
diagnostic,
diag
Copy link
Member

Choose a reason for hiding this comment

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

Consider if we could make the equivalent enum items correspond to a single value like:

Suggested change
quiet,
q,
minimal,
m,
normal,
n,
detailed,
d,
diagnostic,
diag
quiet,
q = quiet,
minimal,
m = minimal,
normal,
n = normal,
detailed,
d = detailed,
diagnostic,
diag = diagnostic,

Which would make tests like verbosity == VerbosityOptions.quiet simpler (no need to check also for VerbosityOptions.q.

Copy link
Member Author

Choose a reason for hiding this comment

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

I do agree with you, but I actually want to rewrite this enum entirely (I have a WIP branch) and handle that as a separate change.

List<ILogger> loggersForBuild = [
MakeTerminalLogger(verbosity)
TerminalLogger.CreateTerminalOrConsoleLogger([$"--verbosity:{LoggerVerbosity.Quiet.ToString().ToLowerInvariant()}", ..buildArgs.OtherMSBuildArgs])
Copy link
Member

Choose a reason for hiding this comment

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

It feels like there could be a shared utility function for this common pattern - creating TerminalLogger from LoggerVerbosity and OtherMSBuildArgs

Copy link
Member Author

Choose a reason for hiding this comment

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

I think you're right - the Testing team especially may like that. @Evangelink?

Copy link
Member

Choose a reason for hiding this comment

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

I actually meant only in this repo, to share the code since I saw it repeating several times.

Copy link
Member Author

Choose a reason for hiding this comment

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

I know - the test team has a lot of similar stuff to run in the test command in this repo :)

Copy link
Member

Choose a reason for hiding this comment

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

cc @dotnet/dotnet-testing

@baronfel baronfel force-pushed the remove-interactive-special-case branch from 3199459 to 9be9a4f Compare July 12, 2025 12:42
@baronfel baronfel merged commit f9748c8 into dotnet:main Jul 13, 2025
27 checks passed
@baronfel baronfel deleted the remove-interactive-special-case branch July 13, 2025 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-CLI untriaged Request triage from a team member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy