提交 c546d4d0 编写于 作者: J Jason Malinowski

Correctly handle two projects specifying the same output path

When we're converting metadata references to output references, if
there are two projects specifying the same output path, we don't do
conversion and instead just keep the reference to the metadata
reference. This was largely becasue we don't have a way to pick between
the two options, and going with "the first" isn't deterministic. There
was a bug though: when we get a second project with the same output path,
we didn't correctly do the conversion of existing references to the
first back, so you'd end up with that project reference dangling.
do the conversion back to
上级 e6a1f440
......@@ -1548,7 +1548,16 @@ public void AddProjectOutputPath(ProjectId projectId, string outputPath)
{
// We have more than one project outputting to the same path. This shouldn't happen but we'll convert back
// because now we don't know which project to reference.
ConvertProjectReferencesToMetadataReferences_NoLock(projectId, outputPath);
foreach (var otherProjectId in projectsForOutputPath)
{
// We know that since we're adding a path to projectId and we're here that we couldn't have already
// had a converted reference to us, instead we need to convert things that are pointing to the project
// we're colliding with
if (otherProjectId != projectId)
{
ConvertProjectReferencesToMetadataReferences_NoLock(otherProjectId, outputPath);
}
}
}
}
}
......
......@@ -37,5 +37,39 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.ProjectSystemShim
project2.RemoveMetadataReference(ReferencePath, MetadataReferenceProperties.Assembly)
End Using
End Sub
<WpfFact>
<WorkItem(857595, "https://dev.azure.com/devdiv/DevDiv/_workitems/edit/857595")>
Public Sub TwoProjectsProducingSameOutputPathBehavesCorrectly()
Using environment = New TestEnvironment()
Dim referencingProject = environment.ProjectFactory.CreateAndAddToWorkspace("referencingProject", LanguageNames.CSharp)
Dim project1 = environment.ProjectFactory.CreateAndAddToWorkspace("project1", LanguageNames.CSharp)
' First: have a single project producing this DLL, and ensure we wired up correctly
Const ReferencePath = "C:\project1.dll"
project1.OutputFilePath = ReferencePath
referencingProject.AddMetadataReference(ReferencePath, MetadataReferenceProperties.Assembly)
Dim getReferencingProject = Function() environment.Workspace.CurrentSolution.GetProject(referencingProject.Id)
Assert.Equal(project1.Id, Assert.Single(getReferencingProject().ProjectReferences).ProjectId)
Assert.Empty(getReferencingProject().MetadataReferences)
' Create a second project referencing this same DLL. By rule, we now don't know which project to reference, so we just convert back to
' a file reference because something is screwed up.
Dim project2 = environment.ProjectFactory.CreateAndAddToWorkspace("project2", LanguageNames.CSharp)
project2.OutputFilePath = ReferencePath
Assert.Empty(getReferencingProject().ProjectReferences)
Assert.Single(getReferencingProject().MetadataReferences)
' Remove project1. We should then be referencing project2
project1.RemoveFromWorkspace()
Assert.Equal(project2.Id, Assert.Single(getReferencingProject().ProjectReferences).ProjectId)
Assert.Empty(getReferencingProject().MetadataReferences)
End Using
End Sub
End Class
End Namespace
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册