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.

  1. 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:

    image
    After that, you can jump to any of your bookmarks from the Task view:
    image
    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!
  2. Code Maps: this requires Visual Studio Enterprise. Open the Architecture menu and select Generate Code Map for Solution.

    image
    You will get a nice diagram showing all dependencies between assemblies in your project:
    image
  3. 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:
    image
  4. 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 ToolsProductivity Power ToolsPowerCommands:
    image
  5. Thread Deadlocks: Visual Studio can show you thread deadlocks while debugging. When debugging a multithreaded app, break it and open DebugWindowsTasks:
    image
    From here, you can flag your code so that it is more clearly visible.
  6. Executing code in Immediate Window: the Immediate Window can be used to run .NET code. While debugging your app, pause it, and select DebugWindowsImmediate:

    image
    You can enter any .NET expressions and variables or even complex expressions and see them evaluated at once.
  7. 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.
    image
    You can have multiple Data Tips, add comments to them:
    image
    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:
    image
  8. Place reusable code in Toolbox: you can add code that you use frequently to the Toolbox. Pin your Toolbox window, highlight your code and drag it to the Toolbox. Even if you are not working in a visual app, the code snippet can be dragged from the Toolbox into your code:
    image
  9. 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:
    image
  10. 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:
    image
    With this, you can also append to current results or show only the file names that match the search pattern.

                             

2 Comments

Add a Comment

As it will appear on the website

Not displayed

Your website