roslyn: OpenSolutionAsync doesn't get include all Facade references needed to compile a project
We try to get a compilation from a project loaded using OpenSolutionAsync, it fails reporting that some references are missing.
var ws = MSBuildWorkspace.Create();
var solution = ws.OpenSolutionAsync(path).Result;
Example:
string pathToDll = @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\Facades\";
var metadataReferences = new string[] {
"System.Runtime.dll",
"System.Threading.Tasks.dll",
"System.Reflection.dll",
"System.Text.Encoding.dll"}.Select(s => MetadataReference.CreateFromFile(pathToDll + s));
solution = solution.AddMetadataReferences(solution.ProjectIds.First(), metadataReferences);
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 23 (17 by maintainers)
I assume that you mean the original workaround is to add the missing references manually by AddMetaDataReferences.
It doesn’t work for me because the idea for the tool I’m working on is: you give it the path to any arbitrary solution and it just does its thing (a source-to-source translation of sorts) to every project in that solution. For some arbitrary solution/project I don’t know what references Roslyn will miss, so I don’t know which references to add. It’s not always “System.Runtime.dll” that is missing. It could be any library.
I could theoretically parse the diagnostics and look for the missing references, or optimistically add a bunch of references and then parse the diagnostics for duplicate references but I was hoping to avoid that.