Frage

I am trying to open the solution and want to refer the project.. but solution.Projects always comes empty. Below is my code. Am I missing something?

var workspace = MSBuildWorkspace.Create(ImmutableDictionary<string, string>.Empty);
var solution = workspace.OpenSolutionAsync(solutionPath).Result;
var project = solution.Projects.FirstOrDefault(p => p.Name == projectName); //Here solution.Projects comes empty(count 0)
War es hilfreich?

Lösung

If I'm reading your comments right, your code is running within Visual Studio, and you're trying to get a workspace to match whatever solution is currently open. In that case, do not use MSBuildWorkspace. MSBuildWorkspace really should never be used inside devenv.exe. Follow the answers to this question which lets you get direct access to the Roslyn model that we've already built up atop the solution model.

Andere Tipps

Make sure that Microsoft.CodeAnalysis.CSharp.Workspaces package is installed. It helped me.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top