I have written a unit test that compiles an external solution. One of the projects in this solution has a COM reference (SHDocVW). When Roslyn tries to compile this project, it gives a compilation error that it cannot resolve this reference.
When I try to do the same thing in a console test application, the compilation succeeds, the COM reference was found.
var solution = msWorkspace.OpenSolutionAsync(solutionPath).Result;
foreach (var project in solution.Projects)
{
var compilation = project.GetCompilationAsync().Result;
var diag = compilation.GetDiagnostics();
if (diag.Any(d => d.Severity == DiagnosticSeverity.Error))
{
Debug.WriteLine($"Error compiling project {project.Name}");
}
}
When I use procmon (of Sysinternals) to see where he tries to resolve the SHDocVW dll, I see that in the case of the console app, he looks in the obj folder of the external solution, where he finds that dll. In case of the unit project, he doesn't even try to resolve the dll. Manually copying the dll to the output folder of the unit test does not change the behaviour.
This behavior can easily be reproduced in a small test project.
I am not sure of this problem is caused by Roslyn, it seems that he just doesn't tries to resolve these COM references during the unit test.
Has anybody any ideas how to resolve this ?