roslyn: MSBuildWorkspace can't compile Class Library referencing PCL
Related to #560 and various dupes #1373, #2700, #1894
We first noticed this problem when trying to compile XUnit with MSBuildWorkspace
. All the Desktop projects failed to build but all the PCLs were fine.
To repro:
- Create new ClassLibrary project (I’ve called mine Desktop)
- Create new PortableClassLibrary project (I’m called mine PortableClassLibrary)
- Create reference to PortableClassLibrary in ClassLibrary
- The projects must interact in some way. For example:
In the ClassLibrary I use the following:
namespace Desktop
{
public class Class1
{
public void MyMethod()
{
var test = new PortableClassLibrary.Class1();
var obj = test.PCLMethod();
}
}
}
And in the PCL:
namespace PortableClassLibrary
{
public class Class1
{
public object PCLMethod()
{
return new object();
}
}
}
Now in another solution try to compile the above with Roslyn:
var msws = MSBuildWorkspace.Create(new Dictionary<string, string> { { "CheckForSystemRuntimeDependency", "true" } });
var soln = msws.OpenSolutionAsync(@"C:\Users\Josh\Documents\GitHub\Orange\Desktop\Desktop.sln").Result;
var comp = soln.Projects.First().GetCompilationAsync().Result;
var errs = comp.GetDiagnostics().Where(n => n.Severity == DiagnosticSeverity.Error).ToList();
//One error
Expected: Project builds without errors (as it does in Visual Studio).
Actual: We receive the following error:
C:\Users\Josh\Documents\GitHub\Orange\Desktop\Desktop\Class1.cs(14,23): error CS0012: The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 1
- Comments: 16 (15 by maintainers)
Links to this issue
Commits related to this issue
- Do run ResolveProjectReferences in MSBuildWorkspace Things like ImplicitlyExpandFacadeReferences depend on it being set. Fixes #2824. — committed to Pilchie/roslyn by Pilchie 9 years ago
One note: We receive the error regardless of whether or not
CheckForSystemRuntimeDependency
is set to true or omitted.