Skip to content

Fix nuget subcommand --help forwarding to NuGet CLI#53723

Merged
marcpopMSFT merged 5 commits intomainfrom
copilot/fix-nuget-add-source-help
Apr 17, 2026
Merged

Fix nuget subcommand --help forwarding to NuGet CLI#53723
marcpopMSFT merged 5 commits intomainfrom
copilot/fix-nuget-add-source-help

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 6, 2026

Fixes #53673

dotnet nuget add source --help (and all nuget subcommand help) showed the generic System.CommandLine help for the nuget command instead of forwarding to the NuGet CLI. Regression in 11.0 SDK.

Root Cause

DotnetHelpBuilder.Write() used this guard to detect NuGet commands:

if (command.GetRootCommand() is NuGetCommandDefinition)

GetRootCommand() traverses all the way to the actual CLI root (DotNetCommandDefinition), so this check is always false. The code falls through to base.Write(context), showing the generic System.CommandLine help for the nuget command.

Fix

Replace the broken check with a proper ancestor traversal:

if (IsInNuGetCommandTree(command))

private static bool IsInNuGetCommandTree(Command command)
{
    if (command is NuGetCommandDefinition) return true;
    if (command.Parents.FirstOrDefault(p => p is Command) is Command parent)
        return IsInNuGetCommandTree(parent);
    return false;
}

This correctly handles all cases:

  • Unregistered subcommands like nuget add source (where the matched command is NuGetCommandDefinition itself, with unmatched tokens)
  • Registered direct subcommands (NuGetDeleteCommandDefinition, etc.)
  • Deeply nested subcommands (NuGetTrustAuthorCommandDefinition, etc.)

The condition `command.GetRootCommand() is NuGetCommandDefinition` was always
false because `GetRootCommand()` traverses all the way up to
`DotNetCommandDefinition` (the actual root), not to `NuGetCommandDefinition`.

Replace it with `IsInNuGetCommandTree(command)` which correctly traverses
the parent chain to check if the command is within the NuGet subtree.

Agent-Logs-Url: https://github.com/dotnet/sdk/sessions/f678f3d7-f807-4a5a-9900-e20baeb4a0a0

Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix help output for dotnet nuget add source Fix nuget subcommand --help forwarding to NuGet CLI Apr 6, 2026
Copilot AI requested a review from marcpopMSFT April 6, 2026 21:57
@marcpopMSFT marcpopMSFT marked this pull request as ready for review April 10, 2026 17:26
@marcpopMSFT marcpopMSFT requested review from baronfel and Copilot April 10, 2026 17:26
@marcpopMSFT marcpopMSFT enabled auto-merge April 10, 2026 17:28
@marcpopMSFT marcpopMSFT requested a review from MiYanni April 10, 2026 17:28
@marcpopMSFT
Copy link
Copy Markdown
Member

Confirmed locally. Tested in codespaces with a few different nuget commands and it works well there.

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

Fixes a regression in the .NET 11 SDK where dotnet nuget <subcommand> --help displayed generic System.CommandLine help instead of forwarding to the NuGet CLI help output.

Changes:

  • Replaces the incorrect GetRootCommand()-based NuGet detection with an ancestor traversal (IsInNuGetCommandTree).
  • Ensures NuGet help forwarding triggers for both registered and unregistered (unmatched-token) NuGet subcommand paths.

Comment thread src/Cli/dotnet/Parser.cs Outdated
Comment thread src/Cli/dotnet/Parser.cs
marcpopMSFT and others added 2 commits April 10, 2026 16:57
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Comment thread src/Cli/dotnet/Parser.cs
auto-merge was automatically disabled April 14, 2026 17:59

Head branch was pushed to by a user without write access

@marcpopMSFT marcpopMSFT merged commit 7baa9ec into main Apr 17, 2026
18 of 20 checks passed
@marcpopMSFT marcpopMSFT deleted the copilot/fix-nuget-add-source-help branch April 17, 2026 18:27
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.

Not showing subcommand help for "dotnet nuget add source --help" in 11.0 SDK

5 participants