-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Conversation
f08dad9
to
9d8a0c9
Compare
52bd9c3
to
c2053ad
Compare
Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
c2053ad
to
2612e77
Compare
@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? |
Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
Fixed the test expectation to use the full project path format. The test now expects
Fixed the test expectation to use the full project path format. The test now expects Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
@@ -25,7 +25,7 @@ public PackageRemoveCommand( | |||
_arguments = parseResult.GetValue(PackageRemoveCommandParser.CmdPackageArgument).ToList().AsReadOnly(); | |||
if (_fileOrDirectory == null) | |||
{ | |||
throw new ArgumentNullException(nameof(_fileOrDirectory)); | |||
_fileOrDirectory = Environment.CurrentDirectory; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this makes sense. But I don't know the code well enough to evaluate that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MiYanni I tested locally and it appears to work:
(dogfood) PS C:\test\repro> dotnet package remove System.Text.json
info : Removing PackageReference for package 'System.Text.json' from project 'C:\test\repro\repro.csproj'.
If I test the case of there is no .csproj, the error is good to:
(dogfood) PS C:\test\repro\obj> dotnet package remove System.Text.json
Could not find any project in C:\test\repro\obj
.
.Fail(); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing final new line. According to the .editorconfig
in the root of the repo
[*]
insert_final_newline = true
Line 10 in 806e650
insert_final_newline = true |
And no later rule overrides it to
false
and I found no .editorconfig
closer to the source.
I think it would be a good idea to ask Copilot to run dotnet format
on the code it produces to make sure it matches the repos established rules (at least when it's creating completely new files (otherwise dotnet format
could cause noise)).
@@ -25,7 +25,7 @@ public PackageRemoveCommand( | |||
_arguments = parseResult.GetValue(PackageRemoveCommandParser.CmdPackageArgument).ToList().AsReadOnly(); | |||
if (_fileOrDirectory == null) | |||
{ | |||
throw new ArgumentNullException(nameof(_fileOrDirectory)); | |||
_fileOrDirectory = Environment.CurrentDirectory; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fwiw, my PR #49635 will fix this issue as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Were you going to add a test for this scenario? Feel free to copy the ones below in but I don't see one in your PR that fixes this. Looks like you do default to CurrentDirectory in the case of both a file and project option are missing. I'll close this PR in favor of yours.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will copy the tests from here, thanks.
fixed by jjonesz change |
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: