Logo
BUG: EnvDTE.UIHierarchyItems does not work correctly in Visual Studio 2005 if Solution Explorer nodes are not opened previously

Author: Carlos J. Quintero (Microsoft MVP) Applies to: Microsoft Visual Studio 2005
Date: April 2007    
       
Introduction

When using a macro or add-in in VS 2005 to iterate the nodes of the Solution Explorer, some nodes inside solution folders are not returned if you didn't expand them previously by hand.

Cause

This seems to be a bug of Visual Studio 2005.

More Information

Steps to reproduce the problem:

  • Create a macro like the following, which iterates recursively the nodes of the solution explorer:
    Sub NavigateSolutionExplorerHierarchy()
        NavigateUIHierarchyItems(DTE.ToolWindows.SolutionExplorer.UIHierarchyItems)
    End Sub
    Private Sub NavigateUIHierarchyItems(ByVal colUIHierarchyItems As UIHierarchyItems)
        For Each objUIHierarchyItem As UIHierarchyItem In colUIHierarchyItems
            System.Windows.Forms.MessageBox.Show(objUIHierarchyItem.Name)
            NavigateUIHierarchyItems(objUIHierarchyItem.UIHierarchyItems)
        Next
    End Sub
  • Create a blank solution in Visual Studio 2005 ("Other Project Types", "Visual Studio Solutions").
  • Add to the solution a solution folder (such as "NewFolder1").
  • Add to the solution folder a child solution folder (such as "NewFolder11").
  • Add a project (such as "ClassLibrary1") to the child solution folder ("NewFolder11").
  • Collapse the child solution folder ("NewFolder11") in the Solution Explorer.
  • Collapse the solution folder ("NewFolder1") in the Solution Explorer.
  • Close the solution (saving the changes).
  • Open the solution again. The nodes in the Solution Explorer are collapsed.
  • Run the macro. Notice that the project node ("ClassLibrary1") is not listed.
  • Expand all the nodes in the Solution Explorer.
  • Run the macro again. This time the project node ("ClassLibrary1") is listed.


Go to the 'Visual Studio Extensibility (VSX)' web site for more articles like this (Articles section)