Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fix dotnet remove package project argument not recognized - #53401

#53401
Merged
martinrrm merged 1 commit into
maindotnet/sdk:mainfrom
dev-martinrrm-fix-dotnet-remove-package-workingdirdotnet/sdk:dev-martinrrm-fix-dotnet-remove-package-workingdirCopy head branch name to clipboard
Mar 12, 2026
Merged

Fix dotnet remove package project argument not recognized#53401
martinrrm merged 1 commit into
maindotnet/sdk:mainfrom
dev-martinrrm-fix-dotnet-remove-package-workingdirdotnet/sdk:dev-martinrrm-fix-dotnet-remove-package-workingdirCopy head branch name to clipboard

Conversation

@martinrrm

Copy link
Copy Markdown
Contributor

Fixes: NuGet/Home#14801

NuGet Product Used

dotnet.exe

Product Version

.NET SDK Version: 10.0.300-preview.26126.103

Worked before?

It is a regression since it doesn’t repro on VS Main/11405.173 + NuGet Client Dev/7.3.0.51.

Impact

It's more difficult to complete my work

Repro Steps & Context

Note:

  1. Repro rate: 100%.
  2. The command 'dotnet add [ProjectFilePath] package xxx' in step 2 can be run successfully.

Repro Steps:

  1. Create a solution folder (called CMD in this instance) and cd to the folder in ‘Developer Command Prompt for VS’.
  2. Run the command one by one as below.
dotnet new console -n MyApp 
dotnet restore --use-lock-file MyApp\MyApp.csproj 
dotnet new classlib -n MyLib 
dotnet add MyLib\MyLib.csproj package NUnit --version 4.4.0 
dotnet add MyApp\MyApp.csproj reference MyLib\MyLib.csproj
dotnet restore MyApp\MyApp.csproj 
dotnet add MyApp\MyApp.csproj package NUnit --version 4.4.0 
dotnet restore MyApp\MyApp.csproj 
  1. Run the command below to remove the package:
    dotnet remove MyApp\MyApp.csproj package NUnit

Expected Result:

No error occurs and the package is removed successfully.

Actual Result:

An error ‘could not find any project’ occurs as the red line in the screenshot below.

Image

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

Fixes a regression where dotnet remove <project> package <name> fails to recognize the positional project/file argument, causing “could not find any project” when invoked from outside the project directory. This aligns dotnet remove package behavior with the existing path-resolution logic used by other package commands.

Changes:

  • Wire the positional <PROJECT | FILE> argument into PackageRemoveCommand path processing (matching the PackageAddCommand pattern).
  • Extend PackageRemoveCommandDefinitionBase with a GetProjectOrFileArgument() hook so hidden dotnet remove package can reuse the parent command’s positional argument.
  • Add a regression test covering dotnet remove <relative project path> package <package>.

Reviewed changes

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

File Description
test/dotnet.Tests/CommandTests/Package/Remove/GivenDotnetRemovePackage.cs Adds coverage for removing a package when the project is provided positionally via a relative path.
src/Cli/dotnet/Commands/Package/Remove/PackageRemoveCommand.cs Passes the positional project/file argument into ProcessPathOptions so the command resolves the intended project.
src/Cli/Microsoft.DotNet.Cli.Definitions/Commands/Package/PackageRemoveCommandDefinition.cs Introduces GetProjectOrFileArgument() on the remove command definition base (returns null for dotnet package remove).
src/Cli/Microsoft.DotNet.Cli.Definitions/Commands/Hidden/Remove/RemovePackageCommandDefinition.cs Supplies the parent RemoveCommandDefinition.ProjectOrFileArgument so hidden dotnet remove package honors the positional project/file argument.

You can also share your feedback on Copilot code review. Take the survey.

@nkolev92 nkolev92 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.

main goes to 11.0.100.

So this will probably need ported to wherever the regression happened.

@martinrrm
martinrrm merged commit b98e0dd into main Mar 12, 2026
32 checks passed
@martinrrm
martinrrm deleted the dev-martinrrm-fix-dotnet-remove-package-workingdir branch March 12, 2026 16:56
Scrambles56 added a commit to Givenwell/avro-nuget that referenced this pull request May 3, 2026
The :10.0 floating tag now resolves to SDK 10.0.203, which has a
regression in `dotnet remove <proj> package <name>` (returns
"Could not find any project") — see dotnet/sdk#53401, port #53418
still unmerged. Pin to the digest used by the last known-good build
of Givenwell/Events (run 22832784599) until the fix lands upstream.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

4 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.