MSBuildWorkspace.Create似乎不能正常工作 [英] MSBuildWorkspace.Create seems to be not working properly

查看:760
本文介绍了MSBuildWorkspace.Create似乎不能正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图打开该解决方案,并希望参考项目..但solution.Projects永远是空的。
下面是我的代码。
我缺少的东西。



  VAR工作区= MSBuildWorkspace.Create(ImmutableDictionary<字符串,字符串> .Empty)?; 
VAR解决方案= workspace.OpenSolutionAsync(solutionPath)。结果;
VAR项目= solution.Projects.FirstOrDefault(P => p.Name ==项目名); //这里solution.Projects自带空(计数0)


解决方案

如果我读您的评论的权利,你的代码是Visual Studio中运行,并且你正在试图获得一个工作区,以匹配任何解决方案是当前打开的。在这种情况下,做的的使用MSBuildWorkspace。 MSBuildWorkspace真的不应该内部devenv.exe的使用。按照答案这个问题它可以让你到了,我们已经建立了解决方案模型之上的罗斯林模型的直接访问。


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.

这篇关于MSBuildWorkspace.Create似乎不能正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆