[英]Is there a way to select a project using ENVDTE?
I want to add a Service reference to a project using ENVDTE. 我想使用ENVDTE向项目添加服务引用。 The only way is by the following command which pops up the Add service Reference window:
唯一的方法是通过以下命令弹出“添加服务参考”窗口:
_applicationObject.ExecuteCommand("Project.AddServiceReference", string.Empty);
But this command will work only on currently selected project. 但是此命令仅适用于当前选择的项目。 Is there a way to select a particular project where the service reference is to be added?
有没有一种方法可以选择要添加服务引用的特定项目?
DTE2.SelectedProjects
has no way to select a project, it only helps to retrieve selected projects. DTE2.SelectedProjects
无法选择项目,它只能帮助检索选定的项目。
You have to navigate through the solution tree like this : 您必须像这样浏览解决方案树:
var se = _applicationObject.ToolWindows.SolutionExplorer;
var proj = se.GetItem("PathToYourProject");
proj.Select(vsUISelectionType.vsUISelectionTypeSelect);
After you launch your command. 启动命令后。
PathToYourProject is a "pseudo" XPath. PathToYourProject是一个“伪” XPath。 If you're workging in a project called "Project" in a solution called "Solution" your path will be : "Solution\\Project"
如果您在名为“解决方案”的解决方案中处理名为“项目”的项目,那么您的路径将是:“解决方案\\项目”
Take care if your project is in a solution folder. 如果您的项目在解决方案文件夹中,请当心。 It's a little bit more tricky.
有点棘手。 You have to expand solution folder like this :
您必须像这样展开解决方案文件夹:
var solutionFolder = se.GetItem("PathToYourSolutionFolder");
if (!solutionFolder .UIHierarchyItems.Expanded)
{
solutionFolder .UIHierarchyItems.Expanded = true;
}
Then you retrieve and select your project by this way : 然后,您可以通过以下方式检索并选择您的项目:
var proj = solutionFolder .UIHierarchyItems.Item("ProjectName");
proj.Select(vsUISelectionType.vsUISelectionTypeSelect);
Finally, I'm not sure, but you may have to select the "Service References" node of your project before to launch the command. 最后,我不确定,但是您可能必须在启动命令之前选择项目的“服务引用”节点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.