diff --git a/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTestBase.cs b/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTestBase.cs index 66637d5bbf..9252df450d 100644 --- a/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTestBase.cs +++ b/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTestBase.cs @@ -77,7 +77,8 @@ protected static Task TestNoChangeforProject( TestFile[]? additionalFiles = null, MockNuGetPackage[]? packages = null, ExperimentsManager? experimentsManager = null, - string projectFilePath = "test-project.csproj") + string projectFilePath = "test-project.csproj", + ExpectedUpdateOperationResult? expectedResult = null) => TestUpdateForProject( dependencyName, oldVersion, @@ -88,7 +89,8 @@ protected static Task TestNoChangeforProject( additionalFiles, additionalFilesExpected: additionalFiles, packages: packages, - experimentsManager: experimentsManager); + experimentsManager: experimentsManager, + expectedResult: expectedResult); protected static Task TestUpdateForProject( string dependencyName, diff --git a/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.PackageReference.cs b/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.PackageReference.cs index d28af3270a..ead8755bcf 100644 --- a/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.PackageReference.cs +++ b/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.PackageReference.cs @@ -3109,6 +3109,46 @@ await TestNoChangeforProject("Some.Package", "7.0.1", "13.0.1", ); } + [Fact] + public async Task NoChange_IfPeerDependenciesCannotBeEvaluated() + { + // make sure we don't throw if we find conflicting peer dependencies; this can happen in multi-tfm projects if the dependencies are too complicated to resolve + // eventually this should be able to be resolved, but currently we can't branch on the different packages for different TFMs + await TestNoChangeforProject("Some.Package", "1.0.0", "1.1.0", + packages: + [ + // initial packages + new MockNuGetPackage("Some.Package", "1.0.0", + DependencyGroups: [ + ("net8.0", [("Transitive.Dependency", "8.0.0")]), + ("net9.0", [("Transitive.Dependency", "9.0.0")]) + ]), + MockNuGetPackage.CreateSimplePackage("Transitive.Dependency", "8.0.0", "net8.0"), + MockNuGetPackage.CreateSimplePackage("Transitive.Dependency", "9.0.0", "net9.0"), + + // what we're trying to update to, but will fail + new MockNuGetPackage("Some.Package", "1.1.0", + DependencyGroups: [ + ("net8.0", [("Transitive.Dependency", "8.1.0")]), + ("net9.0", [("Transitive.Dependency", "9.1.0")]) + ]), + MockNuGetPackage.CreateSimplePackage("Transitive.Dependency", "8.1.0", "net8.0"), + MockNuGetPackage.CreateSimplePackage("Transitive.Dependency", "9.1.0", "net9.0"), + ], + projectContents: """ + + + net8.0;net9.0 + + + + + + """, + expectedResult: new() // success + ); + } + [Fact] public async Task ProcessingProjectWithWorkloadReferencesDoesNotFail() { diff --git a/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/PackageReferenceUpdater.cs b/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/PackageReferenceUpdater.cs index fc911fb132..1ebdc4aeba 100644 --- a/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/PackageReferenceUpdater.cs +++ b/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/PackageReferenceUpdater.cs @@ -61,6 +61,11 @@ public static async Task UpdateDependencyAsync( } else { + if (peerDependencies is null) + { + return; + } + await UpdateDependencyWithConflictResolution(repoRootPath, buildFiles, tfms, projectPath, dependencyName, previousDependencyVersion, newDependencyVersion, isTransitive, peerDependencies, logger); }