-
Notifications
You must be signed in to change notification settings - Fork 719
PrunePackageReference improvements - restore applies PrivateAssets=all and IncludeAssets=none to all prunable direct references #6545
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
base: dev
Are you sure you want to change the base?
Conversation
50c6e59
to
962db6f
Compare
962db6f
to
93e1489
Compare
Added When you commit this breaking change:
You can refer to the .NET SDK breaking change guidelines |
@NuGet/nuget-client |
static bool IsDependencyPruned(LibraryDependency dependency, IReadOnlyDictionary<string, PrunePackageReference> packagesToPrune) | ||
{ | ||
if (packagesToPrune?.TryGetValue(dependency.Name, out PrunePackageReference packageToPrune) == true | ||
&& dependency.LibraryRange.VersionRange.Satisfies(packageToPrune.VersionRange.MaxVersion)) | ||
{ | ||
return true; | ||
} | ||
return false; | ||
} |
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.
We can reduce verbosity and make it more concise:
static bool IsDependencyPruned(LibraryDependency dependency, IReadOnlyDictionary<string, PrunePackageReference> packagesToPrune) | |
{ | |
if (packagesToPrune?.TryGetValue(dependency.Name, out PrunePackageReference packageToPrune) == true | |
&& dependency.LibraryRange.VersionRange.Satisfies(packageToPrune.VersionRange.MaxVersion)) | |
{ | |
return true; | |
} | |
return false; | |
} | |
static bool IsDependencyPruned(LibraryDependency dependency, IReadOnlyDictionary<string, PrunePackageReference> packagesToPrune) | |
{ | |
return packagesToPrune?.TryGetValue(dependency.Name, out var packageToPrune) == true | |
&& dependency.LibraryRange.VersionRange.Satisfies(packageToPrune.VersionRange.MaxVersion); | |
} |
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.
There was similar question in an previous PR, that implementation slows down debugging, since now you need to set a conditional breakpoint vs just setting a breakpoint.
Functionally they're the same, so no perf benefit.
From a readability perspective, I've always seen them as equivalent as well, especially in this case.
If you feel strongly I can change it, especially both you and Nigusu brought it up (although I'm guessing @zivkan will lean towards the current version, as that's something we've discussed previously)
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.
yes, I personally dislike return statements that do anything other than return a const or a variable, because I often want to inspect the value when debugging. The compiled code is the same, so I just see it as unhelpful code golf 😆
I'm fine with bool result = ...
followed by return result;
if we want to remove the if statement. But I just don't like combining the two into a single statement.
src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/IncludeFlagUtils.cs
Outdated
Show resolved
Hide resolved
src/NuGet.Core/NuGet.ProjectModel/PackageSpecReferenceDependencyProvider.cs
Outdated
Show resolved
Hide resolved
static bool IsDependencyPruned(LibraryDependency dependency, IReadOnlyDictionary<string, PrunePackageReference> packagesToPrune) | ||
{ | ||
if (packagesToPrune?.TryGetValue(dependency.Name, out PrunePackageReference packageToPrune) == true | ||
&& dependency.LibraryRange.VersionRange.Satisfies(packageToPrune.VersionRange.MaxVersion)) | ||
{ | ||
return true; | ||
} | ||
return false; | ||
} |
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.
It looks like this code is a duplicate of IncludeFlagUtils.IsDependencyPruned
. This indicates to me that we could benefit from a data structure that handles the pruned dependency case and reduce the if conditionals. In lieu of that, we should deduplicate the 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.
It is duplicated, but there's no type that would naturally own this, since TargetFrameworkInformation itself is a model and it has a dict of prune package refs.
The other consideration why I didn't add a type is that the feature is in development, so I didn't have enough scenarios to come up with an API.
Maybe I do now, but as of right now I've landed in the camp of I'd rather have 2 copies than a bad API.
1e1ed65
to
f3375d3
Compare
Bug
Fixes: NuGet/Home#14196
Description
Builds on top of #6540.
Design in NuGet/Home#14325.
This PR ensures that pruning privatizes direct packages .
This is the final of the pruning for directs work. Note that we have a P7 urgency and we're trying
PR Checklist