- Notifications
You must be signed in to change notification settings - Fork1.2k
Auto-enable DOTNET_CLI_CONTEXT_VERBOSE for diagnostic verbosity#52222
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:release/10.0.2xx
Are you sure you want to change the base?
Conversation
Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
…n accessCo-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
baronfel commentedDec 16, 2025
@copilot a solution that requires every command to remember to call some method is not workable - instead you should use the Doing this keeps the behavior consistent across all commands that use the verbosity. |
Per@baronfel's feedback, moved verbosity handling to an Action on theVerbosityOption itself. This eliminates the need for each command tomanually call ApplyVerbosityOptions(). The Action is attached to allVerbosityOption variants and will be invoked by System.CommandLinewhen the option is parsed.Changes:- Added ApplyVerbosityAction class in CommonOptions- Added Action property to all VerbosityOption definitions- Reverted all command-specific verbosity handling code- Kept IsDiagnostic() extension method for reuseCo-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
I've refactored the implementation to use the Option Action pattern as you suggested. The ApplyVerbosityAction is now attached to all VerbosityOption definitions in CommonOptions, and all the per-command calls have been reverted (commit47b9106). However, I'm finding that the Action doesn't appear to be invoked during testing. Could you clarify when System.CommandLine invokes Option Actions? Is there something specific I need to do to ensure the Action is called when the option is parsed? |
The Action needs Terminating = false so that command executioncontinues after the action runs. Verified that DOTNET_CLI_CONTEXT_VERBOSEis now properly set to "True" when using -v diag or -v diagnostic acrossbuild, restore, and other commands.Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
- Removed commented debug statements- Simplified success case in enum parsing- All functionality remains working as verified by testsCo-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
baronfel commentedDec 16, 2025
@copilot the 'pre-actions' are collected during parsinghere, and then invoked sequentially during command invocationhere. your implementation of the action needs to change slightly - you don't need to do all of this work to get the verbosity, you can just directly fetch the value from the parse result. If the action is being invoked you canassume that the verbosity is in the parse result. if you pass a reference to the verbosity option to the Action, then you can do something like |
Per@baronfel's feedback, refactored ApplyVerbosityAction to acceptthe verbosity option as a constructor parameter. This allows directuse of parseResult.GetValue(verbosityOption) instead of searchingthrough all children.Changes:- Made ApplyVerbosityAction generic to handle both VerbosityOptions and VerbosityOptions? types- Pass option reference to Action constructor- Simplified Invoke logic to directly get value from parse result- Changed HiddenVerbosityOption from field to property to support proper initialization with ActionVerified working with dotnet build/restore -v diagCo-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
Updated the implementation to pass the option reference to the Action as you suggested (commite7a82e7). The Action now uses |
baronfel left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This LGTM - the CI failure is the WinRT known issue
Uh oh!
There was an error while loading.Please reload this page.
Implementation Complete
The solution uses System.CommandLine's Option Action mechanism with a generic Action class that receives the option reference directly. This allows cleaner code using
parseResult.GetValue(verbosityOption)as suggested by@baronfel.Verified working:
dotnet build -v diag✓dotnet restore -v diagnostic✓dotnet build -v normal(does not set variable) ✓Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our2 minute survey.