Skip to content

Suppress default values for .NET CLI flag options - #55928

Merged
marcpopMSFT merged 10 commits into
mainfrom
copilot/fix-unknown-switch-ucr-issue
Sep 25, 2026
Merged

marcpopMSFT merged 10 commits into
mainfrom
copilot/fix-unknown-switch-ucr-issue

Conversation

Copilot AI commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

CLI flags such as --ucr are presence-only options, but help output displayed [default: False], suggesting they accept boolean values. This was inconsistent across commands and obscured that --use-current-runtime false is not valid flag syntax.

  • Help rendering

    • Suppress defaults for zero-arity bool options.
    • Preserve defaults for boolean options that accept a value.
  • Flag definitions

    • Declare dotnet solution add --in-root and --include-references as zero-arity flags.
  • Coverage

    • Update help-output baselines.
    • Add formatter-level coverage distinguishing flags from value-taking booleans.
--ucr, --use-current-runtime  Use current runtime as the target runtime.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
3 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI changed the title [WIP] Fix unknown switch ucr for restore and publish commands Suppress default values for .NET CLI flag options Aug 25, 2026
Copilot AI requested a review from marcpopMSFT August 25, 2026 21:23
@baronfel
baronfel marked this pull request as ready for review August 25, 2026 21:42
Copilot AI lite review requested due to automatic review settings August 25, 2026 21:42
@baronfel
baronfel requested review from a team as code owners August 25, 2026 21:42
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
2 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@baronfel baronfel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is pretty much what I was hoping to see, @marcpopMSFT!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 updates .NET SDK CLI help rendering so presence-only bool flags no longer display [default: False] in --help output, and adjusts some dotnet solution add option definitions accordingly. It also refreshes help-output baselines and adds a focused test to distinguish zero-arity flags from value-taking boolean options.

Changes:

  • Suppress default-value rendering for zero-arity bool Options in the CLI help formatter.
  • Update dotnet command help baselines to remove [default: False] for flag options.
  • Change dotnet solution add option arities for --in-root / --include-references and add a formatter-level regression test.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/dotnet.Tests/CommandTests/Solution/List/GivenDotnetSlnList.cs Updates help baseline to remove [default: False] from a boolean flag option.
test/dotnet.Tests/CommandTests/Solution/Add/GivenDotnetSlnAdd.cs Updates help baseline for dotnet sln add, reflecting changed default rendering.
test/dotnet.Tests/CommandTests/Reference/Add/GivenDotnetAddReference.cs Updates help baseline to remove [default: False] for --interactive.
test/dotnet.Tests/CommandTests/Package/Remove/GivenDotnetRemovePackage.cs Updates help baseline to remove [default: False] for --interactive.
test/dotnet.Tests/CommandTests/MSBuild/GivenDotnetMSBuildBuildsProjects.cs Adds a regression test validating default suppression for zero-arity boolean options.
src/Cli/Microsoft.DotNet.Cli.Definitions/Help/HelpBuilder.Default.cs Implements default suppression logic for zero-arity boolean options in help formatting.
src/Cli/Microsoft.DotNet.Cli.Definitions/Commands/Solution/SolutionAddCommandDefinition.cs Changes dotnet sln add option arities (notably --in-root / --include-references).

Comment on lines 33 to 37
{
Description = CommandDefinitionStrings.SolutionAddReferencedProjectsOptionDescription,
DefaultValueFactory = (_) => true,
Arity = ArgumentArity.Zero,
};
@marcpopMSFT

Copy link
Copy Markdown
Member

This is pretty much what I was hoping to see, @marcpopMSFT!

@baronfel looking through the behavior here, I think it's shown us a few cases where we can remove flags. --interactive is always on as is --include-references. Those flags don't do anything anymore (they were once off by default). Since they don't take a bool, you can't set them to false. Should we just remove them from the help for those commands?

We could make them hidden so as not to break existing customers or just remove in 12 entirely. Thoughts? (or should we make them full booleans?)

@baronfel

baronfel commented Aug 27, 2026 •

Copy link
Copy Markdown
Member

IMO interactive needs a forcing capability so it needs a boolean - we don't currently have a way to force non-interactive the way we can force interactivity. The other two examples from this PR are less impactful and could be hidden for a release. It's probably to late to remove them entirely.

@marcpopMSFT

Copy link
Copy Markdown
Member

@copilot it looks like --interactive is now on by default so the existing flag doesn't make sense anymore. Can you change that to be a boolean option so customers can do --interactive false?

Additionally, any other flags that are on by default like --include-references we should just hide since they don't make a difference anymore? The interactive one we want to keep but the rest that are already default to on can be hidden.

Copilot AI commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

@copilot it looks like --interactive is now on by default so the existing flag doesn't make sense anymore. Can you change that to be a boolean option so customers can do --interactive false?

Additi...

Implemented in dc824eb: --interactive now accepts an optional boolean value, including --interactive false; the default-on --include-references flag is hidden while its flag spelling remains accepted.

@marcpopMSFT

Copy link
Copy Markdown
Member

@copilot fix the tests that are failing:

  • PrintCliSchema_WritesExpectedJson
  • CanShowHelp_Install
  • CanShowHelp_Uninstall
  • CanShowHelp_List
  • CanShowHelp_Search
  • CanShowHelp_Update
  • CanShowHelp_Create
  • CanShowHelp
  • VerifyMTPHelpOutput

Co-authored-by: marcpopMSFT <[email protected]>
Copilot AI requested review from a team as code owners August 27, 2026 23:50

Copilot AI commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

@copilot fix the tests that are failing:

  • PrintCliSchema_WritesExpectedJson
    ...

Fixed in cecd2f4. Updated the CLI schema, dotnet-new help approvals, and MTP help snapshot to retain defaults only for value-taking booleans.

@Evangelink Evangelink left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Review findings are in the inline comments.

Copilot AI requested a review from a team as a code owner August 28, 2026 21:18

@Evangelink Evangelink left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The existing --include-references compatibility concern still applies to the current head.

Before this change, the integration test explicitly verified that --include-references=false succeeded and suppressed recursive project inclusion. Setting Arity = ArgumentArity.Zero makes that value invalid, while the revised test removes the regression coverage. Hiding the default-on option is compatible; changing its arity is not. Please preserve the value-taking behavior while hiding it, or provide a compatible way to opt out.

I’m not approving this revision while that regression remains.

Note

This review was generated with AI assistance.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 91319485-3056-4ffd-8f48-f06f589c118e
Copilot-Session: 91319485-3056-4ffd-8f48-f06f589c118e
Copilot-Session: 91319485-3056-4ffd-8f48-f06f589c118e

@Evangelink Evangelink left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed the current head with no blocking or warning-level findings. The hidden --include-references option preserves explicit true/false values, shared --interactive false consumers honor the parsed value, and the flag-default suppression is covered across formatter, schema, command help, and approval tests.

Note

This review was generated with AI assistance.

@marcpopMSFT
marcpopMSFT merged commit 3b1d59f into main Sep 25, 2026
23 checks passed
@marcpopMSFT
marcpopMSFT deleted the copilot/fix-unknown-switch-ucr-issue branch September 25, 2026 20:35
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unknown switch ucr, use-current-runtime not working for restore, build and publish

5 participants