Skip to content

Commit

Permalink
pr remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
marcin-krystianc committed Feb 24, 2023
1 parent 82d3109 commit 6e4e758
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/NuGet.Core/NuGet.Commands/RestoreCommand/LockFileBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ private IEnumerable<LibraryDependency> GetLibraryDependenciesForCentralTransitiv
{
foreach (GraphNode<RemoteResolveResult> rootNode in targetGraph.Graphs)
{
var dependencyDictionary = rootNode.Item.Data.Dependencies.ToDictionary(x => x.Name, x => x, StringComparer.OrdinalIgnoreCase);
Dictionary<string, LibraryDependency> dependencyDictionary = null;

foreach (GraphNode<RemoteResolveResult> node in rootNode.InnerNodes)
{
Expand All @@ -527,6 +527,11 @@ private IEnumerable<LibraryDependency> GetLibraryDependenciesForCentralTransitiv
continue;
}

if (dependencyDictionary == null)
{
dependencyDictionary = rootNode.Item.Data.Dependencies.ToDictionary(x => x.Name, x => x, StringComparer.OrdinalIgnoreCase);
}

CentralPackageVersion centralPackageVersion = targetFrameworkInformation.CentralPackageVersions[node.Item.Key.Name];
Dictionary<string, LibraryIncludeFlags> dependenciesIncludeFlags = _includeFlagGraphs[targetGraph];

Expand All @@ -535,7 +540,7 @@ private IEnumerable<LibraryDependency> GetLibraryDependenciesForCentralTransitiv
// Centrally pinned dependencies are not directly declared but the intersection of all of the PrivateAssets of the parents that pulled it in should apply to it
foreach (GraphNode<RemoteResolveResult> dependencyNode in EnumerateNodesForDependencyChecks(rootNode, node))
{
var dependency = dependencyDictionary[dependencyNode.Key.Name];
LibraryDependency dependency = dependencyDictionary[dependencyNode.Key.Name];
suppressParent &= dependency.SuppressParent;
}

Expand Down Expand Up @@ -585,7 +590,8 @@ private static IEnumerable<GraphNode<T>> EnumerateNodesForDependencyChecks<T>( G
{
if (node.OuterNode == rootNode)
{
// It's what we are looking for
// We were traversing the graph upwards and now found a parent node (an inner node of the root node).
// Now we return it, so it can be used to calculate the effective value of SuppressParent for the initial node.
yield return node;
}
else
Expand Down

0 comments on commit 6e4e758

Please sign in to comment.