Skip to content

Fix dotnet package remove command when project is not specified #49314

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 10, 2025

The new dotnet package remove command was throwing an ArgumentNullException when no project was specified, while the equivalent old dotnet remove package command worked correctly.

Issue

# Not working - throws ArgumentNullException
dotnet package remove System.Text.Json

# Working
dotnet remove package System.Text.Json

# Working 
dotnet package remove System.Text.Json --project MyProject.csproj

Root Cause

The PackageRemoveCommand constructor tried to get the project path from two sources:

  1. PackageCommandParser.ProjectOption (--project flag)
  2. RemoveCommandParser.ProjectArgument (from old command structure)

When using the new syntax without --project, both sources returned null because the new command doesn't go through the old remove command parser that has a default value.

Solution

Modified the constructor to default to Environment.CurrentDirectory when both sources are null, matching the expected behavior and consistency with other dotnet commands.

Changes:

  • PackageRemoveCommand.cs: Replace ArgumentNullException with default to current directory (1 line changed)
  • GivenDotnetPackageRemove.cs: Add comprehensive test coverage for the new command syntax

The fix is minimal and surgical, maintaining all existing functionality while enabling the expected behavior when no project is specified.

Fixes #49313.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 8xbvsblobprodcus382.vsblob.vsassets.io
    • Triggering command: dotnet test test/dotnet.Tests/dotnet.Tests.csproj --filter GivenDotnetRemovePackage --verbosity normal (dns block)
  • bcnvsblobprodcus378.vsblob.vsassets.io
    • Triggering command: dotnet test test/dotnet.Tests/dotnet.Tests.csproj --filter GivenDotnetRemovePackage --verbosity normal (dns block)
  • i1qvsblobprodcus353.vsblob.vsassets.io
    • Triggering command: dotnet test test/dotnet.Tests/dotnet.Tests.csproj --filter GivenDotnetRemovePackage --verbosity normal (dns block)
  • l49vsblobprodcus358.vsblob.vsassets.io
    • Triggering command: dotnet test test/dotnet.Tests/dotnet.Tests.csproj --filter GivenDotnetRemovePackage --verbosity normal (dns block)
  • mfjvsblobprodcus373.vsblob.vsassets.io
    • Triggering command: dotnet test test/dotnet.Tests/dotnet.Tests.csproj --filter GivenDotnetRemovePackage --verbosity normal (dns block)
  • s4uvsblobprodcus326.vsblob.vsassets.io
    • Triggering command: dotnet test test/dotnet.Tests/dotnet.Tests.csproj --filter GivenDotnetRemovePackage --verbosity normal (dns block)
  • x3yvsblobprodcus370.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/sdk/sdk/.dotnet/dotnet msbuild /m /nologo /clp:Summary /v:minimal /nr:true /warnaserror /p:TreatWarningsAsErrors=true /p:ContinuousIntegrationBuild=false /home/REDACTED/work/sdk/sdk/artifacts/toolset/restore.proj /t:__WriteToolsetLocation /clp:ErrorsOnly;NoSummary /p:__ToolsetLocationOutputFile=/home/REDACTED/work/sdk/sdk/artifacts/toolset/10.0.0-beta.25304.106.txt (dns block)
    • Triggering command: dotnet test test/dotnet.Tests/dotnet.Tests.csproj --filter GivenDotnetRemovePackage --verbosity normal (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@Copilot Copilot AI changed the title [WIP] dotnet package remove throws an error if the project is not specified Fix dotnet package remove command when project is not specified Jun 10, 2025
@Copilot Copilot AI requested a review from marcpopMSFT June 10, 2025 17:52
Copilot finished work on behalf of marcpopMSFT June 10, 2025 17:52
Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
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.

dotnet package remove throws an error if the project is not specified
2 participants