문제

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)
도움이 되었습니까?

해결책

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.

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top