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ôi và biê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?
[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 *. –
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. –