Visual Studio Find Current File in Solution Explorer
The Visual Studio Solution Explorer panel is like home for Visual Studio users. It presents all projects, source files and items thanks to a treeview layout. This panel is quite sophisticated and it is likely that you don't use all the power of this great tool. Let's present the top 10 productivity tips related to the Visual Studio Solution Explorer.
Short GIF animation is an excellent way to quickly learn Visual Studio productivity tips. See others related posts based also on short GIFs here:
- 10 Visual Studio Solution Explorer Productivity Tips
- 10 Visual Studio Ninja Code Editor Productivity Tips
- 12 Visual Studio Debugging Productivity Tips
- Top 10 Visual Studio Refactoring Tips
- 10 Visual Studio Navigation Productivity Tips
- 10 Visual Studio Files and Layout Productivity Tips
- 14 Visual Studio Web Development Productivity Tips
1) Automatically Track active Item in Solution Explorer
On a large Visual Studio solution with hundreds or thousands of source files, the Visual Studio Solution Explorer button Sync with Active Document is often clicked to find your way.
This sync can be done automatically. For that you just need to check: Visual Studio > top menus > Tools > Options… > Projects and Solutions > General > Track Active Item in Solution Explorer .
2) Improve Visual Studio Startup Performance
Visual Studio startup is faster with these 3 settings:
- Allow parallel project initialization checked
- Reopen documents on solution load unchecked
- Restore Solution Explorer project hierarchy state on solution load unchecked
This tip is especially useful to accelerate Visual Studio Startup when opening a large solution.
3) Search in Visual Studio Solution Explorer
The shortcut Ctrl+; set the focus in the Visual Studio Solution Explorer search textbox and you can start typing your search term(s). If the Solution Explorer panel is not visible this shortcut makes it visible. When displaying search results the treeview hierarchy is kept so you know the location of matched items.
The search setting Search within file contents is set by default but can be turned off to restreint the search on file name only.
The search setting Search within external items is set by default to match files in External Dependencies folders. Turning it off prevents searching within the C/C++ External Dependencies folder. This setting is not related to C#, VB.NET and F# projects.
4) Browse Types, Methods and Fields
In Visual Studio Solution Explorer a source file item can be expanded to browse type(s), methods and fields declared in the source file. Types, methods and fields items are shown in the same order of their declarations in the source file. These items can be double-clicked to open the source declaration and right-clicked to show the related menus.
5) Filter File Opened or Pending Changes
Two filters are proposed:
- Open Files Filter: This filter is especially useful when a code review or a change spawn on many files.
- Pending Changes Filter: Often a refactoring session spawn on several files and this filter lets keep track of file changed.
It is also possible to create your own filter as explained in this documentation: Extend the Solution Explorer filter
6) Quickly Set the Startup Project
Most developers I know setup the startup project this way: 1) find the project in the Solution Explorer 2) right click the project and find in the long list of menus the Set as Startup Project menu.
Here is a quicker way : select the Solution item, Alt+Enter shortcut to view the Solution Property Pages dialog, there you can quickly chose the startup project in a combo-box and even define multiple startup projects:
7) Preview Selected Items on Project
When the checkbox Preview Selected Items is checked, when selecting a source file it is automatically opened in the preview tab. This feature is widely used but what you might not know is that this feature also work to open project files XML content!
8) Scope to a Single Project
Often a development session only concerns a single project. You can restreint the Visual Studio Solution Explorer to only a single project with the project right-click menu Scope to This.
9) Multiple Solution Explorer Views
I wish that the Scope to This facility shown above would be available when right-clicking several projects to restreint the focus on a few projects, but it is not.
However it is possible to work with multiple solution explorer views, each one scoping to a project. To do so right-click a project and click the menu New Solution Explorer View. Notice that extra Solution Explorer View(s) are not persisted. When you close and re-open Visual Studio they are not here anymore.
10) Switch to Folder Views
Most of the time the Visual Studio Solution Explorer displays assets structured in a logical way. For example solution folders used to group projects don't necessarily represent real OS file system folders. It is often useful to switch to a physical presentation of the solution folders and files. This can be achieved with the Switch Views combo box.
11) Bonus: Explore Solution Architecture
The new NDepend powerful dependency graph is like a second Solution Explorer that focuses on the solution architecture. Folders and files can be drag-and-dropped from the Visual Studio Solution Explorer to the graph.
There are many more facilities presented in the videos below:
- It can handle live very large solutions made of dozens or hundreds of projects.
- Right clicking a solution explorer item like a project or a source file shows a menu to generate a graph of the item's child, callers and callees.
- Box size in the graph is proportional to the number of lines of code to get an intuitive view.
- Items in the graph can be searched, expanded and collapsed the same way as in the Visual Studio Solution Explorer.
- The graph has a navigation bar to quickly generate call graph, coupling graph, class diagram, graph of dependency cycles, graph of changes since baseline and more.
My dad being an early programmer in the 70's, I have been fortunate to switch from playing with Lego, to program my own micro-games, when I was still a kid. Since then I never stop programming.
I graduated in Mathematics and Software engineering. After a decade of C++ programming and consultancy, I got interested in the brand new .NET platform in 2002. I had the chance to write the best-seller book (in French) on .NET and C#, published by O'Reilly and also did manage some academic and professional courses on the platform and C#.
Over my consulting years I built an expertise about the architecture, the evolution and the maintenance challenges of large & complex real-world applications. It seemed like the spaghetti & entangled monolithic legacy concerned every sufficiently large team. As a consequence, I got interested in static code analysis and started the project NDepend.
Today, with more than 12.000 client companies, including many of the Fortune 500 ones, NDepend offers deeper insight and full control on their application to a wide range of professional users around the world.
I live with my wife and our twin kids Léna and Paul in the beautiful island of Mauritius in the Indian Ocean.
Visual Studio Find Current File in Solution Explorer
Source: https://blog.ndepend.com/10-visual-studio-solution-explorer-productivity-tips/