0

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 ?

  • `MSBuildWorkspace` has some troubles with projects, [see](https://github.com/dotnet/roslyn/issues/13859) and [see](https://stackoverflow.com/questions/42562142/roslyn-not-finding-all-references). Maybe it helps to you. – George Alexandria Jul 02 '17 at 19:11
  • The code to load and compile the solution in a MSBuildWorkspace is the same in the unit test as in the console application. In the console application the compilation works, and in the unit test it does not. So it doesn't seems to be a problem with the MSBuildWorkspace on it's own. – Tom De Vree Jul 03 '17 at 06:44

1 Answers1

0

It looks like you don't have Microsoft.Build.Utilities.Core.dll is in your output folder.

Install-Package Microsoft.Build.Utilities.Core -Version 15.1.1012

Abhishek
  • 621
  • 1
  • 8
  • 19