提交 2c049e8d 编写于 作者: J Jason Malinowski

Don't convert metadata references to P2P references if we don't support compilation

If you had a F# project opened with the new project system, it'd supply
an output directory which other projects (like C#) could reference.
If you had a C# project that referenced the F# project, any attempt
to get the C# compilation would crash because we can't actually produce
F# compilations. The fix is simple: don't convert from metadata
references.
上级 4ea427f2
......@@ -7,6 +7,7 @@
using System.IO;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces;
using Microsoft.CodeAnalysis.Host;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.LanguageServices.CSharp.ProjectSystemShim;
......@@ -76,6 +77,22 @@ public static CPSProject CreateCSharpCPSProject(TestEnvironment environment, str
return cpsProject;
}
public static CPSProject CreateNonCompilableProject(TestEnvironment environment, string projectName, string projectFilePath)
{
var hierarchy = environment.CreateHierarchy(projectName, projectFilePath, "");
return CPSProjectFactory.CreateCPSProject(
environment.ProjectTracker,
environment.ServiceProvider,
hierarchy,
projectName,
projectFilePath,
Guid.NewGuid(),
NoCompilationConstants.LanguageName,
commandLineParserService: null,
binOutputPath: null);
}
private static string GetOutputPathFromArguments(string[] commandLineArguments)
{
const string outPrefix = "/out:";
......
......@@ -135,5 +135,29 @@ public void AddingProjectReferenceAndUpdateReferenceBinPath()
project1.Disconnect();
}
}
[WorkItem(461967, "https://devdiv.visualstudio.com/DevDiv/_workitems/edit/461967")]
[WpfFact()]
[Trait(Traits.Feature, Traits.Features.ProjectSystemShims)]
public void AddingMetadataReferenceToProjectThatCannotCompileInTheIdeKeepsMetadataReference()
{
using (var environment = new TestEnvironment())
{
var project1 = CreateCSharpProject(environment, "project1");
environment.ProjectTracker.UpdateProjectBinPath(project1, null, @"c:\project1.dll");
var project2 = CreateNonCompilableProject(environment, "project2", @"C:\project2.fsproj");
environment.ProjectTracker.UpdateProjectBinPath(project2, null, @"c:\project2.dll");
project1.OnImportAdded(@"c:\project2.dll", "project2");
// We shoudl not have converted that to a project reference, because we would have no way to produce the compilation
Assert.Empty(project1.GetCurrentProjectReferences());
project2.Disconnect();
project1.Disconnect();
}
}
}
}
\ No newline at end of file
......@@ -794,6 +794,17 @@ protected bool CanAddProjectReference(ProjectReference projectReference)
var project = this.ProjectTracker.GetProject(projectReference.ProjectId);
if (project != null)
{
// We won't allow project-to-project references if this one supports compilation and the other one doesn't.
// This causes problems because if we then try to create a compilation, we'll fail even though it would have worked with
// a metadata reference. If neither supports compilation, we'll let the reference go through on the assumption the
// language (TypeScript/F#, etc.) is doing that intentionally.
if (this.Language != project.Language &&
this.ProjectTracker.WorkspaceServices.GetLanguageServices(this.Language).GetService<ICompilationFactoryService>() != null &&
this.ProjectTracker.WorkspaceServices.GetLanguageServices(project.Language).GetService<ICompilationFactoryService>() == null)
{
return false;
}
// cannot add a reference to a project that references us (it would make a cycle)
return !project.TransitivelyReferences(this.Id);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册