I'm trying to do semantic analysis on a bit of C# code.
When setting up an AdhocWorkspace for my tests I've found examples that point to using the the assembly location on Type and object.
When I do this I get the following errors in my diagnostics:
[0]: TestIsNotInstanceOfTypeMessage.cs(13,20): 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'.
[1]: TestIsNotInstanceOfTypeMessage.cs(13,13): error CS0012: The type 'Type' 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'.
When I add the following line everything works well:
MetadataReference.CreateFromFile(@"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\v4.6.1\\Facades\\System.Runtime.dll"),
I'm not really happy with a hard coded path in my test project but am unsure how to "get" the 4.6.1 versions of object and Type any other way.
The code below shows the gist of my helper to get an AdhocWorkspace
private static readonly ImmutableArray<MetadataReference> _coreReferences =
ImmutableArray.Create<MetadataReference>(
MetadataReference.CreateFromFile(typeof(Type).Assembly.Location),
MetadataReference.CreateFromFile(typeof(object).Assembly.Location)
private static readonly Project _baseProject = new AdhocWorkspace()
.AddProject("Test", LanguageNames.CSharp)
.AddMetadataReferences(_coreReferences)
.WithCompilationOptions(new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
Some more details:
Visual Studio Community v15.4.0Target framework: .NET 4.6.1Microsoft.CodeAnalysis.CSharp v2.4.0- The main project is a console application, and the test project is a regular library, neither are PCLs