Repository navigation
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.
This should be placed in the <returns /> section of the XML doc comment
nkolev92
left a comment
There was a problem hiding this comment.
Great tests. I was able to correlate each test to one of the scenarios called out!
| <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.
I imagine this matches the NuGet.Commands resource?
| var isValid = msBuild.AreCentralVersionRequirementsSatisfied(packageReferenceArgs); | ||
| if (!isValid) | ||
| { | ||
| return 1; |
There was a problem hiding this comment.
should we throw an exception instead of returning error exit code i.e. 1
There was a problem hiding this comment.
The AreCentralVersionRequirementsSatisfied method will log an error
| } | ||
| } | ||
|
|
||
| // Get VersionOverride if it exisits in the package reference. |
There was a problem hiding this comment.
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.
@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.
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.
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.
The AreCentralVersionRequirementsSatisfied method will log an error
93da94e to
3a90203
Compare
ad0b6f4 to
352ba56
Compare
nkolev92
left a comment
There was a problem hiding this comment.
I think there's one small bug. Looks great other than that.
| 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.
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 packagein 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