0

I am using the following code to open solution, load the project and create the compilation.

 var solution = await workspace.OpenSolutionAsync(solutionPath, new ConsoleProgressReporter());
 Project valueObjectProject = solution.Projects.FirstOrDefault(proj => String.Equals(proj.Name, 
                               "ValueObject", StringComparison.CurrentCultureIgnoreCase));
 var bofCompilation = await valueObjectProject.GetCompilationAsync();

Issue: no of items in valueObjectProject.ProjectReferences and compilation.References is 0, which is not true. The property should show a list of projects on which the ValueObject project depends upon. But, I am getting list of all the microsoft assemblies which the project uses under valueObject.MetadataReferences and compilation.ExternalReferences

Currently, the Diagnostics shows multiple errors of type TypeNotFound because the referenced types are declared in different assemblies. I think this is because the compilation does not have project dependency information. Don't know what is going wrong.

enter image description here enter image description here enter image description here

any help would be highly appreciated.

coder
  • 517
  • 5
  • 13
  • Which version of MSBuild did you register to load the project and which kind of project is it. Common causes of issues like this are: 1.) The correct dependencies to build the project are not on the machine (If visual studio can't build the project neither can MSBuildWorkspace) 2.) You are trying to load a .NET Core project with a .NET Framework MSBuild or vica-a-versa (NOTE: I assume you are following best practices and registering MSBuild via [Microsoft.Build.Locator](https://www.nuget.org/packages/Microsoft.Build.Locator/) and not just copying everything to the output directory) – Jonathon Marolf Feb 06 '20 at 17:58
  • I am using MSBuild 16. This is .net framework 4.6.2 project and Visual Studio is able to build the project. – coder Feb 07 '20 at 03:22

0 Answers0