Detect cycle between root project and transitive dependency in new dependency resolver #6247
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Bug
Fixes: NuGet/Home#14052
Description
The new dependency resolver does not check if a transitive dependency happens to have the same name as the root project and instead replaces the root project in the graph with a dependency with a higher version. When the algorithm then tries to create a flattened graph, it throws a
KeyNotFoundException
trying to find the root project in the resolved graph.This was unintentionally fixed in #6231 which made the root project always have its own ID but during resolution the algorithm now adds the package with the cycle and its detected during the flattening.
This change makes it so the name of the root project is indexed as
0
and then subsequent calls to index it will return the ID of the project. Then during resolution, there's a check to see a transitive dependency has a cyclic relationship with the root project and if so, leaves it out of the resolved graph. During the flattening of the graph, the cycle is then detected and an error message is emitted.PR Checklist