views:

109

answers:

3

I have a solution with about 150 projects. When I open the solution, half of them appear to be randomly opened. I want to open the solution with all the projects collapsed. I want to uncollapse only the one I choose after opening the solution.

How can I do this?

A: 

I work on a product with 100+ projects. I make sln files for each sub-module (a few vcproj / csproj which are related) so that i don't have to open a big large sln file to view the project.

There might be a way to script visual studio to open only in collapsed, but i dont know how. I avoid the problem by just splitting the vcproj / csproj into different sln's and use a build server to build.

Andrew Keith
+1  A: 

I believe the IDE keeps the expand/collapse status from the last time the solution was open. The manual process is to close them all yourself.

Alternatively from here. This will collapse all projects and expand the selected project.

Macros Here is a macro to collapse all projects in a solution and expand the selected project:

1.Select ALT+F8 on your VS2005 IDE to open the macro explorer
2.Right Click MyMacros.
3.Select New module.
4.Type the new module name as CollapseAll
5.Select OK – A new module CollapseAll is created.
6.Right Click CollapseAll Module
7.Select Edit – The Macro IDE is launched.
8.Copy the following Sub and paste it between the module and End module. -- in the Macro IDE (you may need to adjust some lines in order to successfully compile the macro):

Sub CollapseAll()
'NavigateSolution()
' 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
Return
End If

' Get the top node (the name of the solution)
Dim UIHSolutionRootNode As UIHierarchyItem
Dim UIHChildItem As UIHierarchyItem
UIHSolutionRootNode = UIHSolutionExplorer.UIHierarchyItems.Item(1)

' Collapse each project node
Dim UIHItem As UIHierarchyItem
For Each UIHItem In UIHSolutionRootNode.UIHierarchyItems
For Each UIHChildItem In UIHItem.UIHierarchyItems
UIHChildItem.UIHierarchyItems.Expanded = False
Next
UIHItem.UIHierarchyItems.Expanded = False
Next
UIHSolutionRootNode.UIHierarchyItems.Expanded = True

Dim UIHSelectedItem As UIHierarchyItem = UIHSolutionExplorer.SelectedItems(0)
UIHSelectedItem.UIHierarchyItems.Expanded = True
End Sub

Save the module. Now add this macro to the toolbar for easy access.

9.Select Tools -> Customize from the main menu
10.Select the Command tab in the Customize dialog
11.Select Macros
12.Select the CollapseAll macro and drag and drop it on one of VS2005 IDE toolbars. You will see the Macro Name on the ToolBar –
13.Do not Close the Customize Popup window --
14.Right Click the Macro Name on the ToolBar
15.Select Default Style – This will remove the Macro Name on the ToolBar, resulting in a small Rectangle on the ToolBar
16.Right Click the Small Rectangle
17.Select ChangeButtonImage
18.Select one of the images, for example, the HourGlass. You will see the Image on the toolbar.
19.Close the Customize PopUp
20.To test the macro:
1.Select one of the projects in your solution
2.Select the CollapseAll Button on the ToolBar
3.Observe the Solution Explorer will collapse all and will expand the project you have selected.

Dave Barker
Thank you Dave... you are a genius.. it worked great !!!
dotnet-practitioner
A: 

I know that this is not for VS2003, but if you are looking for the same solution in VS2010, Sara Ford blogged about an addin that does this for you:

http://blogs.msdn.com/b/saraford/archive/2010/05/13/collapse-selection-in-solution-explorer-extension-7.aspx