From 6e4e7585385602e1e9caeb62002f75a95bf58c97 Mon Sep 17 00:00:00 2001 From: Marcin Krystianc Date: Fri, 24 Feb 2023 11:48:45 +0100 Subject: [PATCH] pr remarks --- .../NuGet.Commands/RestoreCommand/LockFileBuilder.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/NuGet.Core/NuGet.Commands/RestoreCommand/LockFileBuilder.cs b/src/NuGet.Core/NuGet.Commands/RestoreCommand/LockFileBuilder.cs index a00a62d76c2..48f47aa712e 100644 --- a/src/NuGet.Core/NuGet.Commands/RestoreCommand/LockFileBuilder.cs +++ b/src/NuGet.Core/NuGet.Commands/RestoreCommand/LockFileBuilder.cs @@ -517,7 +517,7 @@ private IEnumerable GetLibraryDependenciesForCentralTransitiv { foreach (GraphNode rootNode in targetGraph.Graphs) { - var dependencyDictionary = rootNode.Item.Data.Dependencies.ToDictionary(x => x.Name, x => x, StringComparer.OrdinalIgnoreCase); + Dictionary dependencyDictionary = null; foreach (GraphNode node in rootNode.InnerNodes) { @@ -527,6 +527,11 @@ private IEnumerable 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 dependenciesIncludeFlags = _includeFlagGraphs[targetGraph]; @@ -535,7 +540,7 @@ private IEnumerable 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 dependencyNode in EnumerateNodesForDependencyChecks(rootNode, node)) { - var dependency = dependencyDictionary[dependencyNode.Key.Name]; + LibraryDependency dependency = dependencyDictionary[dependencyNode.Key.Name]; suppressParent &= dependency.SuppressParent; } @@ -585,7 +590,8 @@ private static IEnumerable> EnumerateNodesForDependencyChecks( 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