sdk
sdk copied to clipboard
Fix dotnet package remove command when project is not specified
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:
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:
- PackageRemoveCommand.cs: Replace
ArgumentNullExceptionwith 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:
- Configure Actions setup steps to set up my environment, which run before the firewall is enabled
- Add the appropriate URLs or hosts to my firewall allow list
@copilot the new test you added is failing because it uses the full path of the project and the test expects a partial. Can you fix the test? Since the path is going to be different on each OS, what is the best fix? Is it sufficient to check everything before the project name?
@copilot the new test you added is failing because it uses the full path of the project and the test expects a partial. Can you fix the test? Since the path is going to be different on each OS, what is the best fix? Is it sufficient to check everything before the project name?
@copilot the new test you added is failing because it uses the full path of the project and the test expects a partial. Can you fix the test? Since the path is going to be different on each OS, what i...
Fixed the test expectation to use the full project path format. The test now expects projectDirectory + Path.DirectorySeparatorChar + "TestAppSimple.csproj" which matches the actual output when the command defaults to the current directory. This follows the same pattern used in the existing GivenDotnetRemovePackage.cs test. Fixed in commit 7fc954b.
@copilot the new test you added is failing because it uses the full path of the project and the test expects a partial. Can you fix the test? Since the path is going to be different on each OS, what i...
Fixed the test expectation to use the full project path format. The test now expects projectDirectory + Path.DirectorySeparatorChar + "TestAppSimple.csproj" which matches the actual output when the command defaults to the current directory. This follows the same pattern used in the existing GivenDotnetRemovePackage.cs test. Fixed in commit 7fc954b.
[!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:
7tjvsblobprodcus341.vsblob.vsassets.io
- Triggering command:
dotnet test test/dotnet.Tests/dotnet.Tests.csproj --filter GivenDotnetPackageRemove.WhenPackageIsRemovedWithoutProjectArgument --verbosity normal(dns block)c78vsblobprodcus322.vsblob.vsassets.io
- Triggering command:
dotnet test test/dotnet.Tests/dotnet.Tests.csproj --filter GivenDotnetPackageRemove.WhenPackageIsRemovedWithoutProjectArgument --verbosity normal(dns block)d0svsblobprodcus381.vsblob.vsassets.io
- Triggering command:
dotnet test test/dotnet.Tests/dotnet.Tests.csproj --filter GivenDotnetPackageRemove.WhenPackageIsRemovedWithoutProjectArgument --verbosity normal(dns block)jd4vsblobprodcus366.vsblob.vsassets.io
- Triggering command:
dotnet test test/dotnet.Tests/dotnet.Tests.csproj --filter GivenDotnetPackageRemove.WhenPackageIsRemovedWithoutProjectArgument --verbosity normal(dns block)l49vsblobprodcus358.vsblob.vsassets.io
- Triggering command:
dotnet test test/dotnet.Tests/dotnet.Tests.csproj --filter GivenDotnetPackageRemove.WhenPackageIsRemovedWithoutProjectArgument --verbosity normal(dns block)lylvsblobprodcus31.vsblob.vsassets.io
- Triggering command:
dotnet test test/dotnet.Tests/dotnet.Tests.csproj --filter GivenDotnetPackageRemove.WhenPackageIsRemovedWithoutProjectArgument --verbosity normal(dns block)uy6vsblobprodcus34.vsblob.vsassets.io
- Triggering command:
dotnet test test/dotnet.Tests/dotnet.Tests.csproj --filter GivenDotnetPackageRemove.WhenPackageIsRemovedWithoutProjectArgument --verbosity normal(dns block)vb4vsblobprodcus33.vsblob.vsassets.io
- Triggering command:
dotnet test test/dotnet.Tests/dotnet.Tests.csproj --filter GivenDotnetPackageRemove.WhenPackageIsRemovedWithoutProjectArgument --verbosity normal(dns block)If you need me to access, download, or install something from one of these locations, you can either:
- Configure Actions setup steps to set up my environment, which run before the firewall is enabled
- Add the appropriate URLs or hosts to my firewall allow list
fixed by jjonesz change