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?
By default, the Solution Explorer tool window appears as a pane in the upper-right side of the Visual Studio integrated development environment (IDE). If you don't see the Solution Explorer tool window, you can open it from the Visual Studio menu bar by using View > Solution Explorer, or by pressing Ctrl+Alt+L.
Nested under it are code files and subfolders containing pictures, data, and documents. You can also get a list of all the references in the project.
To access properties on the solution, right click the solution node in Solution Explorer and choose Properties. In the dialog, you can set project configurations for Debug or Release builds, choose which projects should be the startup project when F5 is pressed, and set code analysis options.
The Solution Explorer window contains a list of the items in the current solution. A solution can contain multiple projects, and each project can contain multiple items. The Solution Explorer displays a hierarchical list of all the components, organized by project.
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;
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With