Avoid NuGet restore cycles
Avoid infinite NuGet restores.
Scenario:
Projects might have a package that sets AssetTargetsFallback value that can cause a certain PackageReference to be included. This package contains a props file that changed the AssetTargetFallback property value, and the PackageReference Condition was no longer true, causing it to be removed. Once removed, the AssetTargetFallback value from the csproj was used again, causing an infinite restore -> design time build -> restore loop.
This change:
Since DotNet ProjectSystem can detect changes in NuGet restores by calculating a hash, we can use this hash to detect changes in AssetTargetFallBack and check when this value gets repeated.
This pr makes use of the NuGetRestoreCycleDetector to keep the last N hashes, and once it detects a repeated value (cycle) Dotnet ProjectSystem can stop NuGet restores.
Microsoft Reviewers: Open in CodeFlow
Any updates on this change @ocallesp?
@ocalles You're getting build failures with these changes.
(CoreCompile target) ->
D:\a\_work\1\s\src\Microsoft.VisualStudio.ProjectSystem.Managed.VS\ProjectSystem\VS\PackageRestore\PackageRestoreDataSource.cs(7,44): error CS0234: The type or namespace name 'Implementation' does not exist in the namespace 'Microsoft.VisualStudio.ProjectSystem' (are you missing an assembly reference?)
D:\a\_work\1\s\src\Microsoft.VisualStudio.ProjectSystem.Managed.VS\ProjectSystem\VS\PackageRestore\PackageRestoreDataSource.cs(55,26): error CS0246: The type or namespace name 'IInfoBarService' could not be found (are you missing a using directive or an assembly reference?)
D:\a\_work\1\s\src\Microsoft.VisualStudio.ProjectSystem.Managed.VS\ProjectSystem\VS\PackageRestore\PackageRestoreDataSource.cs(68,13): error CS0246: The type or namespace name 'IInfoBarService' could not be found (are you missing a using directive or an assembly reference?)
@ocalles You're getting build failures with these changes.
(CoreCompile target) -> D:\a\_work\1\s\src\Microsoft.VisualStudio.ProjectSystem.Managed.VS\ProjectSystem\VS\PackageRestore\PackageRestoreDataSource.cs(7,44): error CS0234: The type or namespace name 'Implementation' does not exist in the namespace 'Microsoft.VisualStudio.ProjectSystem' (are you missing an assembly reference?) D:\a\_work\1\s\src\Microsoft.VisualStudio.ProjectSystem.Managed.VS\ProjectSystem\VS\PackageRestore\PackageRestoreDataSource.cs(55,26): error CS0246: The type or namespace name 'IInfoBarService' could not be found (are you missing a using directive or an assembly reference?) D:\a\_work\1\s\src\Microsoft.VisualStudio.ProjectSystem.Managed.VS\ProjectSystem\VS\PackageRestore\PackageRestoreDataSource.cs(68,13): error CS0246: The type or namespace name 'IInfoBarService' could not be found (are you missing a using directive or an assembly reference?)
Fixed. I added the implementation of the InfoBar service as part of this pr.
Tests: Open a solution having an invalid NuGet package. Cycle was detected. Open roslyn and orchardcore. No cycles detected.
Any updates on this change @ocallesp?
Today I add a new commit with the implementation of InfoBar. This pr is complete. Waiting for reviewers and approval
@ocallesp - not required for the initial merge but anyways we can add telemetry around this for when we detect a cyclic restore? Will help determine how often our users run into this scenario, we detect it & display the infobar
Some of the pending code review suggestions will be fixed as part of https://github.com/dotnet/project-system/issues/8389