I am working on a project where I collect projects from a solution using 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);
Compilation contains errors such as
error CS0012: The type "Task" is defined in an assembly that is not a reference. You must add a reference to the assembly 'System.Threading.Tasks, Version = 4.0.0.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a ".
Why won't Roslyn accept the existing mscorlib link?
Are there some CompilationOptions that I should consider? Per this thread I tried assemblyIdentityComparer: DesktopAssemblyIdentityComparer.Default , but that did not help. I tried to work with metadataReferenceResolver , but could not find much information about this.
Following the solution in Roslyn does not have a reference to System.Runtime I implemented a code that ensures that the project has links to mscorlib.dll, System.Core.dll, System.dll and System.Runtime.dll, so my projects and compilations have links:
Side Note: Link # 7 was added this way. The project already had links # 1, 2, and 3, and removing them and replacing them from C: \ Windows \ Microsoft.NET \ Framework did not solve the problem.
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
- How can I get Roslyn to compile this project?
- Can I use
CompilationOptions ? - Roslyn Question No. 970 related to this?
source share