-
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
Open
Copilot
wants to merge
2
commits into
main
Choose a base branch
from
copilot/fix-49313
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+91
−1
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
test/dotnet.Tests/CommandTests/Package/Remove/GivenDotnetPackageRemove.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
Oops, something went wrong.
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.
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
.