如何使用vs程序包在解决方案资源管理器中获取所选项目的详细信息 [英] How to get the details of the selected item in solution explorer using vs package

查看:76
本文介绍了如何使用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.

这篇关于如何使用vs程序包在解决方案资源管理器中获取所选项目的详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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