-
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
Support for dotnet add package command for CPM projects #4792
Support for dotnet add package command for CPM projects #4792
Conversation
{ | ||
var project = GetProject(packageReferenceArgs.ProjectPath); | ||
|
||
// Get package version and VersionOverride if it already exists in the props file. Returns null if there is no matching package version. |
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 should be placed in the <returns />
section of the XML doc comment
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
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 tests. I was able to correlate each test to one of the scenarios called out!
@@ -757,4 +757,8 @@ Non-HTTPS access will be removed in a future version. Consider migrating to 'HTT | |||
<value>PackageReference for package '{0}' added to '{1}' and PackageVersion added to central package management file '{2}'.</value> | |||
<comment>0 - The package ID. 1 - Directory.Packages.props file path. 2 - Project file path.</comment> | |||
</data> | |||
<data name="Error_CPM_AddPkg_VersionsNotAllowed" xml:space="preserve"> |
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 imagine this matches the NuGet.Commands resource?
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
Show resolved
Hide resolved
var isValid = msBuild.AreCentralVersionRequirementsSatisfied(packageReferenceArgs); | ||
if (!isValid) | ||
{ | ||
return 1; |
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.
should we throw an exception instead of returning error exit code i.e. 1
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.
The AreCentralVersionRequirementsSatisfied
method will log an error
} | ||
} | ||
|
||
// Get VersionOverride if it exisits in the package reference. |
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.
Can we use a similar logic like restore?
I don't necessarily think we should expose public API and call it from here, but given that they are trying to assert the same thing, they should have the same code.
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.
@nkolev92 In this case we dont want to look at the dgspec like we do in restore, I know this command uses a dgspec we dont know if it is up to date with the project file, since this tools is modifying the project XML, that should be the source of truth.
The user can modify the XML without doing a restore and try to add a package.
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.
The dgspec is generated prior to the add package command running, so whether a restore was run shouldn't be relevant: https://github.com/dotnet/sdk/blob/a3d79ddc395389d0fe3f3ff9023bbf492323a606/src/Cli/dotnet/commands/dotnet-add/dotnet-add-package/Program.cs#L71-L99
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 changed some of the functionality to check in the dgspec, I'm still checking in csproj and Directory.Package.props files to see if the property comes from the desired file, I wasnt able to check this from the dgspec
var isValid = msBuild.AreCentralVersionRequirementsSatisfied(packageReferenceArgs); | ||
if (!isValid) | ||
{ | ||
return 1; |
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.
The AreCentralVersionRequirementsSatisfied
method will log an error
93da94e
to
3a90203
Compare
ad0b6f4
to
352ba56
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.
I think there's one small bug. Looks great other than that.
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
string directoryPackagesPropsPath = project.GetPropertyValue(DirectoryPackagesPropsPathPropertyName); | ||
|
||
// Get VersionOverride if it exisits in the package reference. | ||
IEnumerable<LibraryDependency> dependenciesWithVersionOverride = packageSpec.TargetFrameworks.SelectMany(tfm => tfm.Dependencies.Where(d => !d.AutoReferenced && d.VersionOverride != null)); |
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.
nit: A more performant version would be to have this after line 137 as you don't really need it beyond the scenarios in which package override is disabled.
78fda17
to
4122ec4
Compare
3a90203
to
207a9eb
Compare
4122ec4
to
3adfc12
Compare
Bug
Fixes: NuGet/Home#9022
Regression? Last working version:
Description
This PR continues work from NuGet/Home#11890 and finishes the rest of scenarios for the command
dotnet add package
in a CPM project.Scenarios 1-4 were added by Pragnya in #4700 and merged into the feature branch. This PR adds support for scenarios 9-16 (5-8 are not possible).
Design spec: https://github.com/NuGet/Home/blob/dev/proposed/2022/cpm-dotnet-cli-add-package-support.md
PR Checklist
PR has a meaningful title
PR has a linked issue.
Described changes
Tests
Documentation