diff --git a/src/VisualStudio/Core/Test.Next/Services/ServiceHubServicesTests.cs b/src/VisualStudio/Core/Test.Next/Services/ServiceHubServicesTests.cs index 32c1f79810c4a..987204412186e 100644 --- a/src/VisualStudio/Core/Test.Next/Services/ServiceHubServicesTests.cs +++ b/src/VisualStudio/Core/Test.Next/Services/ServiceHubServicesTests.cs @@ -307,6 +307,54 @@ await solution.State.GetChecksumAsync(CancellationToken.None), await remoteWorkspace.CurrentSolution.State.GetChecksumAsync(CancellationToken.None)); } + [Fact] + [WorkItem(52578, "https://github.com/dotnet/roslyn/issues/52578")] + public async Task TestIncrementalUpdateHandlesReferenceReversal() + { + using var workspace = CreateWorkspace(); + + using var client = await InProcRemoteHostClient.GetTestClientAsync(workspace).ConfigureAwait(false); + var remoteWorkspace = client.GetRemoteWorkspace(); + + var solution = workspace.CurrentSolution; + solution = AddProject(solution, LanguageNames.CSharp, documents: Array.Empty(), additionalDocuments: Array.Empty(), p2pReferences: Array.Empty()); + var projectId1 = solution.ProjectIds.Single(); + solution = AddProject(solution, LanguageNames.CSharp, documents: Array.Empty(), additionalDocuments: Array.Empty(), p2pReferences: Array.Empty()); + var projectId2 = solution.ProjectIds.Where(id => id != projectId1).Single(); + + var project1ToProject2 = new ProjectReference(projectId2); + var project2ToProject1 = new ProjectReference(projectId1); + + // Start with projectId1 -> projectId2 + solution = solution.AddProjectReference(projectId1, project1ToProject2); + + // verify initial setup + await UpdatePrimaryWorkspace(client, solution); + await VerifyAssetStorageAsync(client, solution, includeProjectCones: false); + + Assert.Equal( + await solution.State.GetChecksumAsync(CancellationToken.None), + await remoteWorkspace.CurrentSolution.State.GetChecksumAsync(CancellationToken.None)); + + // reverse project references and incrementally update + solution = solution.RemoveProjectReference(projectId1, project1ToProject2); + solution = solution.AddProjectReference(projectId2, project2ToProject1); + await UpdatePrimaryWorkspace(client, solution); + + Assert.Equal( + await solution.State.GetChecksumAsync(CancellationToken.None), + await remoteWorkspace.CurrentSolution.State.GetChecksumAsync(CancellationToken.None)); + + // reverse project references again and incrementally update + solution = solution.RemoveProjectReference(projectId2, project2ToProject1); + solution = solution.AddProjectReference(projectId1, project1ToProject2); + await UpdatePrimaryWorkspace(client, solution); + + Assert.Equal( + await solution.State.GetChecksumAsync(CancellationToken.None), + await remoteWorkspace.CurrentSolution.State.GetChecksumAsync(CancellationToken.None)); + } + [Fact] public void TestRemoteWorkspaceCircularReferences() { diff --git a/src/Workspaces/Remote/ServiceHub/Host/RemoteWorkspace.SolutionCreator.cs b/src/Workspaces/Remote/ServiceHub/Host/RemoteWorkspace.SolutionCreator.cs index 37d81cffed904..e650ef41b4af7 100644 --- a/src/Workspaces/Remote/ServiceHub/Host/RemoteWorkspace.SolutionCreator.cs +++ b/src/Workspaces/Remote/ServiceHub/Host/RemoteWorkspace.SolutionCreator.cs @@ -150,7 +150,8 @@ private async Task UpdateProjectsAsync(Solution solution, HashSet UpdateProjectsAsync(Solution solution, HashSet()); + } } // removed project @@ -173,6 +175,19 @@ private async Task UpdateProjectsAsync(Solution solution, HashSet