Skip to main content

Track Files in Visual Studio

By default, Visual Studio’s Solution Explorer will update its selected item based on the currently active document. This is extremely annoying as it keeps expanding your projects and folders until your solution explorer becomes unmanageable and unusable, unless you collapse all Projects (Only available if you have Visual Studio Power Commands) installed) and even then, after collapsing the entire solution, the saga returns back.


Turn off Active tracking

1. Turn your Active tracking off by going to Tools > Options
2. Select “Projects and Solutions” node
3. Uncheck the “Tack Active Item in Solution Explorer”


Add a macro to do on-demand tracking

4. Tools > Marcos > Macro Explorer
5. You will see “MyMacros” Module (Node). Right mouse click on MyMacros and invoke “New Module…”
6. Name it anything you like. I Named it Utilities
7. Right mouse click on Utilizes and invoke “new Macro…” menu. The Macros IDE window opens.
8. Paste in the following into it within the Public Module Utilities statement

Public Sub TrackProjectItem()
DTE.ExecuteCommand("View.TrackActivityinSolutionExplorer", True)
DTE.ExecuteCommand("View.TrackActivityinSolutionExplorer", False)
DTE.ExecuteCommand("View.SolutionExplorer")
End Sub

9. You Macro should look like this.

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90

Public Module UtilitiesPublic Sub TrackProjectItem()
DTE.ExecuteCommand("View.TrackActivityinSolutionExplorer", True)
DTE.ExecuteCommand("View.TrackActivityinSolutionExplorer", False)
DTE.ExecuteCommand("View.SolutionExplorer")
End Sub
End Module

10. Close the Macros IDE Window
11. Right mouse click on MyMacros node within the Macros explorer window and make sure “MyMacros” check for “Set as Recording Project” is checked.
12. Now, bind this macro to a shortcut key of your choice.
    a. Invoke Tools > Options, and Select “Environment” > “keyboard “ node
    b. Type in Macros into the “Show command containing” edit box. Navigate to your macro Macros.MyMacros.Utilities.TrackProjectItem
    c. Put your cursor in the “Press shortcut keys” edit box and press whatever shortcut key you desire. I used F1 since F1 mapped to Help is useless.

'
d. Press “Assign”.

Comments

Popular posts from this blog

Save All/Format All Documents in Visual Studio

Sub FormatAll()    For Each proj As Project In DTE.Solution.Projects      FormatFileRecur(proj.ProjectItems())    Next End Sub Sub FormatFileRecur(ByVal projectItems As EnvDTE.ProjectItems)    For Each pi As EnvDTE.ProjectItem In projectItems      If pi.Collection Is projectItems Then        Dim pi2 As EnvDTE.ProjectItems = pi.ProjectItems        Try          If pi.Name.EndsWith(".cs") Then            If Not (pi.Name.EndsWith("Designer.cs")) Then               If Not pi.IsOpen Then pi.Open(Constants.vsViewKindCode)             pi.Document.Activate()             DTE.ExecuteCommand("Edit.FormatDocum...