-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. I will copy the tests from here, thanks. |
||
} | ||
if (_arguments.Count != 1) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,90 @@ | ||||
// Licensed to the .NET Foundation under one or more agreements. | ||||
// The .NET Foundation licenses this file to you under the MIT license. | ||||
|
||||
using Microsoft.DotNet.Cli.Utils; | ||||
|
||||
namespace Microsoft.DotNet.Cli.Package.Remove.Tests | ||||
{ | ||||
public class GivenDotnetPackageRemove : SdkTest | ||||
{ | ||||
public GivenDotnetPackageRemove(ITestOutputHelper log) : base(log) | ||||
{ | ||||
} | ||||
|
||||
[Fact] | ||||
public void WhenPackageIsRemovedWithoutProjectArgument() | ||||
{ | ||||
var projectDirectory = _testAssetsManager | ||||
.CopyTestAsset("TestAppSimple") | ||||
.WithSource().Path; | ||||
|
||||
var packageName = "Newtonsoft.Json"; | ||||
var add = new DotnetCommand(Log) | ||||
.WithWorkingDirectory(projectDirectory) | ||||
.Execute("add", "package", packageName); | ||||
add.Should().Pass(); | ||||
|
||||
// Test the new 'dotnet package remove' command without specifying project | ||||
var remove = new DotnetCommand(Log) | ||||
.WithWorkingDirectory(projectDirectory) | ||||
.Execute("package", "remove", packageName); | ||||
|
||||
remove.Should().Pass(); | ||||
remove.StdOut.Should().Contain($"Removing PackageReference for package '{packageName}' from project '{projectDirectory + Path.DirectorySeparatorChar}TestAppSimple.csproj'."); | ||||
remove.StdErr.Should().BeEmpty(); | ||||
} | ||||
|
||||
[Fact] | ||||
public void WhenPackageIsRemovedWithProjectOption() | ||||
{ | ||||
var projectDirectory = _testAssetsManager | ||||
.CopyTestAsset("TestAppSimple") | ||||
.WithSource().Path; | ||||
|
||||
var packageName = "Newtonsoft.Json"; | ||||
var add = new DotnetCommand(Log) | ||||
.WithWorkingDirectory(projectDirectory) | ||||
.Execute("add", "package", packageName); | ||||
add.Should().Pass(); | ||||
|
||||
// Test the new 'dotnet package remove' command with --project option | ||||
var remove = new DotnetCommand(Log) | ||||
.WithWorkingDirectory(projectDirectory) | ||||
.Execute("package", "remove", packageName, "--project", "TestAppSimple.csproj"); | ||||
|
||||
remove.Should().Pass(); | ||||
remove.StdOut.Should().Contain($"Removing PackageReference for package '{packageName}' from project 'TestAppSimple.csproj'."); | ||||
remove.StdErr.Should().BeEmpty(); | ||||
} | ||||
|
||||
[Fact] | ||||
public void WhenNoPackageIsPassedCommandFails() | ||||
{ | ||||
var projectDirectory = _testAssetsManager | ||||
.CopyTestAsset("TestAppSimple") | ||||
.WithSource() | ||||
.Path; | ||||
|
||||
var cmd = new DotnetCommand(Log) | ||||
.WithWorkingDirectory(projectDirectory) | ||||
.Execute("package", "remove") | ||||
.Should() | ||||
.Fail(); | ||||
} | ||||
|
||||
[Fact] | ||||
public void WhenMultiplePackagesArePassedCommandFails() | ||||
{ | ||||
var projectDirectory = _testAssetsManager | ||||
.CopyTestAsset("TestAppSimple") | ||||
.WithSource() | ||||
.Path; | ||||
|
||||
var cmd = new DotnetCommand(Log) | ||||
.WithWorkingDirectory(projectDirectory) | ||||
.Execute("package", "remove", "package1", "package2") | ||||
.Should() | ||||
.Fail(); | ||||
} | ||||
} | ||||
} | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing final new line. According to the [*]
insert_final_newline = true Line 10 in 806e650
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 |
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
.