Control when Solution Explorer syncs to the current file

I’ve given many talks on Visual Studio, and one of the most popular questions is about controlling when Solution Explorer syncs to the current item. This extension is the best one I’ve seen in providing this functionality.

To Install

You can find the Solution Explorer Tools extension at http://visualstudiogallery.msdn.microsoft.com/en-us/ef4ac3e9-d056-4383-8ca2-11721bd879b4

To Use

First, you must disable the “Track Active Item in Solution Explorer” in Tools – Options – Projects and Solutions – General page.

Track Active Item in Solution Explorer option disabled

Now the fun can begin.

On the Solution Explorer, you’ll see 3 new icons.

New commands on Solution Explorer

Starting right from left:

  1. Sync Item – sync’s the Solution Explorer to whatever document is open (or the last active item if a tool window is in the file tab channel).
  2. Collapse All – recursively collapses everything in the solution explorer
  3. Collapse to Item – this combines the previous commands. This will sync to the currently opened item and collapse everything else.

You can also bind keyboard shortcuts to each of these commands via the Tools – Options – Keyboard page:

  • Project.SyncItem
  • Project.CollapseItem
  • Project.CollapseToItem

Some keyboard shortcut suggestions are to bind Project.CollapseToItem to Ctrl+Alt+semicolon, since it is right next to the Ctrl+Alt+L keystroke that opens the Solution Explorer. If you really like this feature and want it on all the time, you could bind it to Ctrl+Alt+L, overriding the standard Open Solution Explorer commands, so the Solution Explorer will always open and collapse to the current item.

Just double-check what your keyboard shortcuts are bound to, as your settings may be different than mine.

More information

Check out the extension’s gallery page at http://tinyurl.com/solexp