Over the past few years I've seen developers struggling with the missing feature of collapse all projects in visual studio, there are some macros and add-ins around the net to solve this issue but non of them was good enough for me as most of the solutions collapsed all of the projects.
In my day to day I'm teaching and working with Smart Client Software Factory, the SCSF solution is build using Folders (Source, Infrastructure ... ) which happen to collapse also using the various solutions.
Well, Its time to build a simple macro to do the job my way...
Create a new VS macro solution and paste the following code, assign a hot key (I use Alt-Ctrl-/) and you are done.
Select a node on the solution folder that you want its child to collapse and hit the hot key.
Imports System Imports EnvDTE
Public Module CollapseSelectedNode
' Get the the Solution Explorer tree
Dim UIHSolutionExplorer As UIHierarchy
UIHSolutionExplorer = DTE.Windows.Item(Constants.vsext_wk_SProjectWindow).Object()
' Check if there is any open solution
If (UIHSolutionExplorer.UIHierarchyItems.Count > 0) Then
' Get the selected node
Dim UIHSolutionRootNode As UIHierarchyItem
UIHSolutionRootNode = UIHSolutionExplorer.SelectedItems(0)
UIHSolutionRootNode.DTE.SuppressUI = True
' Collapse each project node
Dim UIHItem As UIHierarchyItem
For Each UIHItem In UIHSolutionRootNode.UIHierarchyItems
If UIHItem.UIHierarchyItems.Count > 0 And UIHItem.UIHierarchyItems.Expanded Then
' As of a Bug in VS 2005 you have to use the following lines
' instead of using UIHItem.UIHierarchyItems.Expended = False
UIHSolutionRootNode.DTE.SuppressUI = False