【发布时间】:2015-04-08 19:18:26
【问题描述】:
我正在开发一个项目,我使用 Roslyn 从解决方案编译项目。
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);
// ...
编译包含错误如
错误 CS0012:类型“任务”是在未定义的程序集中定义的 参考。您必须添加对程序集的引用 'System.Threading.Tasks,版本=4.0.0.0,文化=中性, PublicKeyToken=b03f5f7f11d50a3a'。
为什么 Roslyn 不接受对 mscorlib 的现有引用?
- msdn for System.Threading.Task指出这个类型确实位于mscorlib.dll中
- PublicKeyToken b03f5f7f11d50a3a 匹配 mscorlib 的
我应该考虑一些CompilationOptions 吗?
每this thread 我试过assemblyIdentityComparer: DesktopAssemblyIdentityComparer.Default 但它没有帮助。我尝试与metadataReferenceResolver 合作,但找不到太多相关信息。
按照Roslyn has no reference to System.Runtime 中的解决方案,我实现了确保项目具有对 mscorlib.dll、System.Core.dll、System.dll 和 System.Runtime.dll 的引用的代码,这样我的 项目 和 compilation 有引用:
旁注:参考 #7 已以这种方式添加。该项目已经有引用 #1、2 和 3,将它们删除并替换为 C:\Windows\Microsoft.NET\Framework 中的引用并没有解决问题。
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
- 如何让 Roslyn 编译这个项目?
- 有没有我应该使用的
CompilationOptions? - Roslyn's issue #970 与此有关吗?
【问题讨论】:
-
Resembles this 也是。它仍然是 beta 质量,通过添加参考来跛行。它位于 Facades 子目录中。
-
是的,它与此类似,但此解决方案无法解决问题。我将尝试发布一个发生此问题的最小解决方案。