Skip to content
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

Conversation

pragnya17
Copy link
Contributor

@pragnya17 pragnya17 commented Jun 23, 2022

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

    • Automated tests added
    • Functional test that checks if a package version is added to the props file correctly when there are no existing package versions in the props file already. It also checks that the package reference is added to the project file and that it does not have the package version metadata included in it.
    • Functional test that checks if a package version is added to the props file correctly when there already other existing package versions in the props file. It also checks that the package reference is added to the project file and that it does not have the package version metadata included in it.
    • Functional test that checks if a package version is updated with the correct package version attribute in the Directory.Packages.props file.
  • Documentation

@pragnya17 pragnya17 requested a review from a team as a code owner June 23, 2022 22:49
@kartheekp-ms kartheekp-ms changed the title Dev pragnya17 add package cli support for cpm projects dotnet add package cli support for cpm projects Jun 23, 2022
@pragnya17 pragnya17 force-pushed the dev-pragnya17-AddPackageCLISupportForCPMProjects branch 2 times, most recently from c2074f5 to e83381a Compare June 29, 2022 21:59
Copy link
Member

@nkolev92 nkolev92 left a 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.

Copy link
Member

@nkolev92 nkolev92 left a 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.

@kartheekp-ms kartheekp-ms force-pushed the dev-pragnya17-AddPackageCLISupportForCPMProjects branch from 6236de4 to 48834f8 Compare July 1, 2022 17:44
@jeffkl jeffkl mentioned this pull request Jul 1, 2022
8 tasks
@pragnya17 pragnya17 force-pushed the dev-pragnya17-AddPackageCLISupportForCPMProjects branch from 8455b4f to 9c4e593 Compare July 5, 2022 17:42
@pragnya17
Copy link
Contributor Author

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.

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.

@nkolev92
Copy link
Member

nkolev92 commented Jul 6, 2022

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.

@pragnya17
Copy link
Contributor Author

pragnya17 commented Jul 6, 2022

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.

Copy link
Contributor

@kartheekp-ms kartheekp-ms left a 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.

Comment on lines 178 to 179
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")));
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, will fix that.

@kartheekp-ms
Copy link
Contributor

@pragnya17 - I have updated MSBuildAPIUtilityTests.cs to run only on Windows. All CI checks passed now for this PR. Please feel to merge this pull request. thanks

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);
Copy link
Contributor Author

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)

@pragnya17 pragnya17 merged commit 93da94e into dev-feature-cpm-dotnetaddpackage Jul 12, 2022
@pragnya17 pragnya17 deleted the dev-pragnya17-AddPackageCLISupportForCPMProjects branch July 12, 2022 22:09
martinrrm added a commit that referenced this pull request Sep 28, 2022
* dotnet add package cli support for cpm projects (#4700)
martinrrm added a commit that referenced this pull request Oct 21, 2022
* dotnet add package cli support for cpm projects (#4700)

Co-authored-by: pragnya17 <59893188+pragnya17@users.noreply.github.com>
martinrrm added a commit that referenced this pull request Dec 16, 2022
* dotnet add package cli support for cpm projects (#4700)
martinrrm added a commit that referenced this pull request Dec 21, 2022
* dotnet add package cli support for cpm projects (#4700)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants