2015-04-08 17 views
6

Tôi đang làm việc trên một dự án nơi tôi biên dịch các dự án từ một giải pháp sử dụng Roslyn.Biên dịch Roslyn không giải quyết tài liệu tham khảo mscorlib

foreach (var projectId in solution.GetProjectDependencyGraph().GetTopologicallySortedProjects()) 
{ 
    var project = solution.GetProject(projectId); 
    var compilation = project.GetCompilationAsync().Result; 
    var errors = compilation.GetDiagnostics().Where(d => d.Severity == DiagnosticSeverity.Error); 
    // ... 

Compilation chứa lỗi như

lỗi CS0012: Loại 'Task' được định nghĩa trong một hội đồng đó không phải là tham chiếu. Bạn phải thêm tham chiếu vào assembly 'System.Threading.Tasks, Version = 4.0.0.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a'.

Tại sao Roslyn không chấp nhận tham chiếu hiện có đối với mscorlib?

  • msdn for System.Threading.Task chỉ ra rằng loại hình này thực sự là nằm ở mscorlib.dll
  • PublicKeyToken b03f5f7f11d50a3a phù hợp mscorlib của

Có một số CompilationOptions rằng tôi nên xem xét? Mỗi this thread Tôi đã thử assemblyIdentityComparer: DesktopAssemblyIdentityComparer.Default nhưng không hiệu quả. Tôi đã cố gắng làm việc với metadataReferenceResolver nhưng không thể tìm thấy nhiều thông tin về nó.

Sau khi dung dịch trong Roslyn has no reference to System.Runtime tôi triển khai mã để đảm bảo rằng một dự án có tài liệu tham khảo để mscorlib.dll, System.Core.dll, System.dll và System.Runtime.dll, chẳng hạn dự án tôibiên soạn có tài liệu tham khảo:

Lưu ý phụ: Tham chiếu số 7 đã được thêm theo cách này. Dự án đã có tài liệu tham khảo # 1, 2 và 3, và loại bỏ chúng và thay thế bằng những người từ C: \ Windows \ Microsoft.NET \ Framework đã không giải quyết được vấn đề.

project.MetadataReferences.ToList() 
Count = 8 
    [0]: Assembly Path='C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll' 
    [1]: Assembly Path='C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\mscorlib.dll' 
    [2]: Assembly Path='C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Core.dll' 
    [3]: Assembly Path='C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.dll' 
    [4]: Assembly Path='C:\Users\Amadeus\Documents\GitHub\InterProcessQueue\src\MemoryMappedQueue\packages\xunit.runner.visualstudio.2.0.0-rc1-build1030\build\_common\xunit.abstractions.dll' 
    [5]: Assembly Path='C:\Users\Amadeus\Documents\GitHub\InterProcessQueue\src\MemoryMappedQueue\packages\xunit.assert.2.0.0-rc1-build2826\lib\portable-net45+aspnetcore50+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.assert.dll' 
    [6]: Assembly Path='C:\Users\Amadeus\Documents\GitHub\InterProcessQueue\src\MemoryMappedQueue\packages\xunit.extensibility.core.2.0.0-rc1-build2826\lib\portable-net45+aspnetcore50+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.dll' 
    [7]: Assembly Path='C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Runtime.dll' 

compilation.ExternalReferences.ToList() 
Count = 9 
    [0]: Assembly Path='C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll' 
    [1]: Assembly Path='C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\mscorlib.dll' 
    [2]: Assembly Path='C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Core.dll' 
    [3]: Assembly Path='C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.dll' 
    [4]: Assembly Path='C:\Users\Amadeus\Documents\GitHub\InterProcessQueue\src\MemoryMappedQueue\packages\xunit.runner.visualstudio.2.0.0-rc1-build1030\build\_common\xunit.abstractions.dll' 
    [5]: Assembly Path='C:\Users\Amadeus\Documents\GitHub\InterProcessQueue\src\MemoryMappedQueue\packages\xunit.assert.2.0.0-rc1-build2826\lib\portable-net45+aspnetcore50+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.assert.dll' 
    [6]: Assembly Path='C:\Users\Amadeus\Documents\GitHub\InterProcessQueue\src\MemoryMappedQueue\packages\xunit.extensibility.core.2.0.0-rc1-build2826\lib\portable-net45+aspnetcore50+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.dll' 
    [7]: Assembly Path='C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Runtime.dll' 
    [8]: Compilation (C#): MemoryMappedQueue 
  • Làm thế nào tôi có thể nhận được Roslyn để biên dịch dự án này?
  • Có bất kỳ CompilationOptions nào tôi nên sử dụng không?
  • Có phải là Roslyn's issue #970 liên quan đến điều này không?
+0

[Resembles this] (https://support.microsoft.com/en-us/kb/2971005). Nó vẫn là chất lượng beta, khập khiễng cùng với việc thêm tham chiếu. Nó nằm trong thư mục con * Facades *. –

+0

Có nó giống như thế này nhưng giải pháp này không khắc phục được vấn đề. Tôi sẽ cố gắng đăng một giải pháp tối thiểu nơi vấn đề này xảy ra. –

Trả lời

0

Dự án đang tạo ra lỗi một dự án không di động đang tham chiếu một dự án di động? Nếu vậy, hãy quan sát this answer - bạn sẽ phải thêm tham chiếu mặt tiền.

+0

Không, cả hai dự án trong giải pháp đều là Thư viện lớp nhắm mục tiêu .NET 4.5 –

+0

Thực ra, xunit được tham chiếu.lõi là một PCL –

2

Theo Kevin'sanswer, điều này có thể được giải quyết bằng cách xác định một tài sản cho MSBuildWorkspace:

var props = new Dictionary<string, string>(); 
props["CheckForSystemRuntimeDependency"] = "true"; 
var msWorkspace = MSBuildWorkspace.Create(props); 

Bây giờ các giải pháp mở cửa vào msWorkspace sẽ giải quyết một cách chính xác tài liệu tham khảo của họ.

+1

Điều đó đã không làm việc cho tôi, tôi đang sử dụng VS 2015 RC. Bất kỳ ai? Bất kỳ bản cập nhật? –

Các vấn đề liên quan