我正在开发一个项目,我们正在使用Roslyn为我们编译一些模板.现在,当我正在编译模板时,我收到了多个错误CompileResult.Diagnostics.
错误是:
(21,6): error CS0012: The type 'System.Attribute' 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'.
(21,6): error CS0012: The type 'System.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'.
Run Code Online (Sandbox Code Playgroud)
看到这些错误,我认为我没有System.Runtime正确添加对程序集的引用.但是,在检查加载的组件后,这似乎是有序的.
private IEnumerable<MetadataReference> GetGlobalReferences()
{
var assemblies = new []
{
typeof(System.Object).Assembly, //mscorlib
typeof(System.Composition.ExportAttribute).Assembly, //System.Composition (MEF)
typeof(System.CodeDom.Compiler.CodeCompiler).Assembly, //System.CodeDom.Compiler
};
var refs = …Run Code Online (Sandbox Code Playgroud)