相关疑难解决方法(0)

Roslyn没有引用System.Runtime

我正在开发一个项目,我们正在使用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)

c# roslyn

22
推荐指数
3
解决办法
5888
查看次数

如何使用Roslyn的OpenSolutionAsync解决所有引用?

我正在尝试使用OpenSolutionAsync打开RoslynLight.sln,然后遍历所有项目.为了我的目的,我需要一个语义模型和解决参考.通过这个问题这个问题的结合,我得出了这个部分解决方案:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.MSBuild;
using System.IO;

namespace OpenRoslyn
{
  class Program
  {
    static void Main(string[] args)
    {

      var msbw = MSBuildWorkspace.Create();
      var sln = msbw.OpenSolutionAsync(@"C:\Users\carr27\Documents\GitHub\roslyn\src\RoslynLight.sln").Result;
      //var proj = sln.Projects.First(x => x.Name == "CodeAnalysis.Desktop");
      var messages = new List<string>();
      foreach (var p in sln.Projects)
      {
        Console.WriteLine(p.FilePath);
        messages.Add(p.FilePath);
        var facadesDir = @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\Facades\";
        var proj = p.AddMetadataReference(MetadataReference.CreateFromAssembly(typeof(object).Assembly));
        proj = proj.AddMetadataReference(MetadataReference.CreateFromFile(facadesDir + "System.Runtime.dll"));
        proj = proj.AddMetadataReference(MetadataReference.CreateFromFile(facadesDir …
Run Code Online (Sandbox Code Playgroud)

c# roslyn

5
推荐指数
1
解决办法
3563
查看次数

标签 统计

c# ×2

roslyn ×2