Visual Studio Tips 4
OK, so this is another round of tips on using Visual Studio! See first collection here, second here, the third here and the fifth here.
-
Create shortcuts: you can create shortcuts to frequently used code. Just click <Ctrl>-K-H on any line, and you will add a shortcut to it:
After that, you can jump to any of your bookmarks from the Task view:
To remove it, click <Ctrl>-K-H again in the same line. Note that this is not the same as the bookmarks featured introduced in the third set of tips! -
Code Maps: this requires Visual Studio Enterprise. Open the Architecture menu and select Generate Code Map for Solution.
-
Code Metrics: get a static analysis report of your project, only in Enterprise edition. In the Solution Explorer, right click on your project, Analyze, and select Calculate Code Metrics.
You get an analysis including metrics Maintainability Index, Cyclomatic Complexity, Depth of Inheritance, Class Coupling and Lines of Code, which you can even export to Excel:
-
Format document on save & remove unused and sort using statements on save: Visual Studio can take care of formatting your documents and removing any unnecessary using declarations for you, when you save your documents; you just need to install the Productivity Power Tools extension and enable these options in Tools – Productivity Power Tools – PowerCommands:
-
Thread Deadlocks: Visual Studio can show you thread deadlocks while debugging. When debugging a multithreaded app, break it and open Debug – Windows – Tasks:
From here, you can flag your code so that it is more clearly visible. -
Executing code in Immediate Window: the Immediate Window can be used to run .NET code. While debugging your app, pause it, and select Debug – Windows – Immediate:
- Pin and export Data Tips: while debugging, break and hover any variable or field in your code. Click the pin icon on the right of the tooltip window. This will create a Data Tip.
You can have multiple Data Tips, add comments to them:
Also save Data Tips to files so that they can be loaded in another Visual Studio session, and, of course, load a collection of Data Tips: -
Change C# language version: Visual Studio can use any of the C# versions. For example you may or may not want to use the latest (and greatest, by the way!) features of C# 6. All you have to do is right click on a project, Properties, Build and Advanced. In the Advanced Build Settings window, Language Version, select the one you want to support:
- Find tips: some tips related to the Find functionality. First, you have two results windows, 1 and 2, and you can have your search results appear in any of them:
With this, you can also append to current results or show only the file names that match the search pattern.