-
Notifications
You must be signed in to change notification settings - Fork 694
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
dotnet add package cli support for cpm projects #4700
dotnet add package cli support for cpm projects #4700
Conversation
test/NuGet.Core.Tests/NuGet.ProjectModel.Test/PackageSpecOperationsTests.cs
Outdated
Show resolved
Hide resolved
7c0188c
to
a331f78
Compare
test/NuGet.Core.FuncTests/Dotnet.Integration.Test/DotnetAddPackageTests.cs
Outdated
Show resolved
Hide resolved
test/NuGet.Core.Tests/NuGet.ProjectModel.Test/PackageSpecOperationsTests.cs
Outdated
Show resolved
Hide resolved
src/NuGet.Core/NuGet.CommandLine.XPlat/Utility/MSBuildAPIUtility.cs
Outdated
Show resolved
Hide resolved
src/NuGet.Core/NuGet.CommandLine.XPlat/Utility/MSBuildAPIUtility.cs
Outdated
Show resolved
Hide resolved
src/NuGet.Core/NuGet.CommandLine.XPlat/Utility/MSBuildAPIUtility.cs
Outdated
Show resolved
Hide resolved
test/NuGet.Core.FuncTests/Dotnet.Integration.Test/DotnetAddPackageTests.cs
Outdated
Show resolved
Hide resolved
src/NuGet.Core/NuGet.CommandLine.XPlat/Utility/MSBuildAPIUtility.cs
Outdated
Show resolved
Hide resolved
src/NuGet.Core/NuGet.CommandLine.XPlat/Utility/MSBuildAPIUtility.cs
Outdated
Show resolved
Hide resolved
src/NuGet.Core/NuGet.CommandLine.XPlat/Utility/MSBuildAPIUtility.cs
Outdated
Show resolved
Hide resolved
c2074f5
to
e83381a
Compare
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.
Great job so far.
A few suggestions to improve clarity and I think we might be missing some scenarios.
src/NuGet.Core/NuGet.CommandLine.XPlat/Utility/MSBuildAPIUtility.cs
Outdated
Show resolved
Hide resolved
src/NuGet.Core/NuGet.CommandLine.XPlat/Utility/MSBuildAPIUtility.cs
Outdated
Show resolved
Hide resolved
test/NuGet.Core.FuncTests/Dotnet.Integration.Test/DotnetAddPackageTests.cs
Outdated
Show resolved
Hide resolved
test/NuGet.Core.FuncTests/Dotnet.Integration.Test/DotnetAddPackageTests.cs
Outdated
Show resolved
Hide resolved
test/NuGet.Core.FuncTests/Dotnet.Integration.Test/DotnetAddPackageTests.cs
Show resolved
Hide resolved
test/NuGet.Core.FuncTests/Dotnet.Integration.Test/DotnetAddPackageTests.cs
Show resolved
Hide resolved
test/NuGet.Core.FuncTests/Dotnet.Integration.Test/DotnetAddPackageTests.cs
Show resolved
Hide resolved
test/NuGet.Core.FuncTests/Dotnet.Integration.Test/DotnetAddPackageTests.cs
Show resolved
Hide resolved
src/NuGet.Core/NuGet.CommandLine.XPlat/Utility/MSBuildAPIUtility.cs
Outdated
Show resolved
Hide resolved
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.
This is looking great!
Let's add some no-op and negative tests.
In particular:
What if I specify a --version
where the PackageVersion is already in the DBP.
We should no-op in this case, or do whatever the dotnet add package --version
command does on a standard PackageReference project.
Think about the no-op version of every scenario you implemented.
test/NuGet.Core.FuncTests/Dotnet.Integration.Test/DotnetAddPackageTests.cs
Outdated
Show resolved
Hide resolved
test/NuGet.Core.FuncTests/Dotnet.Integration.Test/DotnetAddPackageTests.cs
Show resolved
Hide resolved
6236de4
to
48834f8
Compare
8455b4f
to
9c4e593
Compare
I assume that by DBP you mean the Directory.Build.props file? However, in the scenarios that I have implemented I assume that the DBP does not exist since it is out of the scope of my project. In this comment, Jeff also mentions that the Directory.Packages.props file is mandatory for onboarding to CPM: NuGet/Home#11903 (comment) . I am happy to create a follow up work item to ensure that we fallback onto existing behavior for the scenario where the Directory.Packages.props file does not exist. |
I meant to write if the version is already in DPP (Directory.Packages.props). I don't really care about the scenarios where the project is not onboarded. |
Makes sense. I actually did already handle the scenario you were talking about (#4700 (review)), I just did not name it properly, so I have now updated the name of the test. For the first 4 scenarios that I implemented, after discussing with @kartheekp-ms and reviewing the spec again (https://github.com/NuGet/Home/blob/dev-kartheekp-ms-cpmaddpackagesupport-revised/proposed/2022/cpm-dotnet-cli-add-package-support.md), I don't believe there are any other no-op/fail scenarios that need to be included in the integration tests. |
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.
Great job. I know CI is failing on other platforms. I will create a separate issue to track that work. Given that this work is getting merged into a feature branch, I will fix the CI scripts before creating a new pull request for merging these changes into the dev branch.
Assert.Contains(@$"<PackageReference Include=""X"" />", File.ReadAllText(Path.Combine(testDirectory, "projectA.csproj"))); | ||
Assert.DoesNotContain(@$"<Version = ""1.0.0"" />", File.ReadAllText(Path.Combine(testDirectory, "projectA.csproj"))); |
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 think we can slightly improve the performance by reading text from the project only once.
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.
Agreed, will fix that.
test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/MSBuildAPIUtilityTests.cs
Outdated
Show resolved
Hide resolved
@pragnya17 - I have updated |
Assert.DoesNotContain(@$"<Version = ""1.0.0"" />", File.ReadAllText(Path.Combine(testDirectory, "projectA.csproj"))); | ||
string updatedProjectFile = File.ReadAllText(Path.Combine(testDirectory, "projectA.csproj")); | ||
Assert.Contains(@$"<PackageReference Include=""X"" />", updatedProjectFile); | ||
Assert.DoesNotContain(@$"<Version = ""1.0.0"" />", updatedProjectFile); |
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.
This always return true, so I think it should be changed to $"PackageReference Includes =""X"" <Version = ""1.0.0"" />". This is along the lines of this comment: #4700 (comment)
* dotnet add package cli support for cpm projects (#4700)
* dotnet add package cli support for cpm projects (#4700) Co-authored-by: pragnya17 <59893188+pragnya17@users.noreply.github.com>
* dotnet add package cli support for cpm projects (#4700)
Bug
Fixes: NuGet/Home#11890
Regression? No.
Description
This feature is based on the design spec: NuGet/Home#11915. The goal was to allow the dotnet add package command to be executed for projects that were onboarded to CPM. Previously, the command threw a NU1008 error whenever packages were attempted to be added to projects onboarded to CPM. However, with this change users will now be able to add or update package references in projects onboarded to CPM. Directory.Packages.props files and project files are now modified accordingly whenever a package is added/updated.
PR Checklist
PR has a meaningful title
PR has a linked issue.
Described changes
Tests
Documentation