Fix dotnet package remove command when project is not specified #49314
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The new
dotnet package remove
command was throwing anArgumentNullException
when no project was specified, while the equivalent olddotnet remove package
command worked correctly.Issue
Root Cause
The
PackageRemoveCommand
constructor tried to get the project path from two sources:PackageCommandParser.ProjectOption
(--project flag)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:
ArgumentNullException
with default to current directory (1 line changed)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
dotnet test test/dotnet.Tests/dotnet.Tests.csproj --filter GivenDotnetRemovePackage --verbosity normal
(dns block)bcnvsblobprodcus378.vsblob.vsassets.io
dotnet test test/dotnet.Tests/dotnet.Tests.csproj --filter GivenDotnetRemovePackage --verbosity normal
(dns block)i1qvsblobprodcus353.vsblob.vsassets.io
dotnet test test/dotnet.Tests/dotnet.Tests.csproj --filter GivenDotnetRemovePackage --verbosity normal
(dns block)l49vsblobprodcus358.vsblob.vsassets.io
dotnet test test/dotnet.Tests/dotnet.Tests.csproj --filter GivenDotnetRemovePackage --verbosity normal
(dns block)mfjvsblobprodcus373.vsblob.vsassets.io
dotnet test test/dotnet.Tests/dotnet.Tests.csproj --filter GivenDotnetRemovePackage --verbosity normal
(dns block)s4uvsblobprodcus326.vsblob.vsassets.io
dotnet test test/dotnet.Tests/dotnet.Tests.csproj --filter GivenDotnetRemovePackage --verbosity normal
(dns block)x3yvsblobprodcus370.vsblob.vsassets.io
/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)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: