如何使用vs程序包在解决方案资源管理器中获取所选项目的详细信息

问题描述:

我正在尝试创建一个VS包,其中已在上下文菜单中添加了一个菜单命令,因此当您在解决方案资源管理器中右键单击某个项目时,它就会出现.现在单击命令,我想显示一个弹出窗口,其中包含该项目的详细信息,您右键单击并调用了该命令.

I am trying to create a VS package in which, I have added a menu command to the context menu, so it appears when you right click an item in the solution explorer. Now on clicking the command, I want to show a pop up with the details of the item, on which you right clicked and invoked the command.

现在我将如何获取有关所选商品的信息?我可以使用任何服务来获取有关该物品的任何详细信息吗?

Now how would I get information about the selected item? Is there any service I can use in order to get any details about the item?

private static EnvDTE80.DTE2 GetDTE2()
    {
        return GetGlobalService(typeof(DTE)) as EnvDTE80.DTE2;
    }
private string GetSourceFilePath()
    {
        EnvDTE80.DTE2 _applicationObject = GetDTE2();
        UIHierarchy uih = _applicationObject.ToolWindows.SolutionExplorer;
        Array selectedItems = (Array)uih.SelectedItems;
        if (null != selectedItems)
        {
            foreach (UIHierarchyItem selItem in selectedItems)
            {
                ProjectItem prjItem = selItem.Object as ProjectItem;
                string filePath = prjItem.Properties.Item("FullPath").Value.ToString();
                //System.Windows.Forms.MessageBox.Show(selItem.Name + filePath);
                return filePath;
            }
        }
        return string.Empty;
    }

以上功能将返回所选项目(文件)的完整路径.基本上是从DTE2实例中获得soultion Explorer,然后您将从中获得有关解决方案资源管理器的所有信息.

Above function will return the selected item(file) full path. basically get the soultion explorer from DTE2 instance and you will get all info about solution explorer from that.