I'm trying out Roslyn for the first time and I'm writing a small piece of code to read through a project, classes and class members.
I'm using the MSBuildWorkspace
class to create the Roslyn workspace (MSBuildWorkspace.Create()
). Below is a small part of the code I've written
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.MSBuild; //Some problem in this line? Read on.
...
...
var workspace = MSBuildWorkspace.Create();
Solution solutionToAnalyze =
workspace.OpenSolutionAsync(pathToSolution).Result;
IEnumerable<Project> projectsToAnalyze =
solutionToAnalyze.Projects;
...
...
When I do a "Go to Definition" on MSBuildWorkspace class, I'm able to navigate to the class's definition and I can clearly see it's namespace to be Microsoft.CodeAnalysis.MSBuild (See image below).
But despite this, I keep getting the error message, "The type or namespace MSBuild doesn't exist in the namespace 'Microsoft.CodeAnalysis' at the using statement that I've highlighted with the comment". I just can't seem to get the reason behind this error. Am I missing anything?