Friday, January 13, 2017

Visual Studio IDE tips

How to add bookmark in MS Visual Studio? 

ctrl + k ctrl + k to add a bookmark at the cursor

ctrl + k ctrl + w  to show all bookmarks


1) Search for file(s) containing the search criteria/term e.g. method name, class name, constants and etc.


"Ctrl ," will open the "Navigator To" dialog. This is very helpful if you want to locate the file associated with your search criteria. This is not allowed while the code is compiling. You have to hold down the ctrl key while pressing ',' .



2) Quickly search and open a file name

If you have a lot of projects or files, and don't know where a particular file existed/located, you can try this trick. To quickly open the file interested, you can do "Ctrl / >of " and enter the file name.


3) To launch a program and debug it at the same time

>devenv /debugexe  fullpath/admintool.exe

This is very useful when you need to troubleshoot the program right before execution. If the program crashes before you have a chance to attach it, mentioned below, then this is the way to go.

4) Useful shortcuts

To set a break point  do ctrl+b  and type in the method name in the dialog like  classname::methodname

Press ctrl key while clicking on a method name will go to the definition of that method. When you press the ctrl key, the method name will be underlined to make it look like a hyperlink.

ctrl+f will format the selected code including auto indentation

alt+b+u will build only the current select project. Or you can add the new menu items to the build menu for compile selected file (ctrl+f7) and link the current project only.


5) Attach to a process for troubleshooting

You can attach to multiple processes.  For example, you can attach to both Admintool and the BI SERVER at the same time if both of these processes are running on the same machine.



Change variable value at breakpoint





Notice you have to put the expression inside the curly braces

Print variable(s) at breakpoint



In order to see the logging information above check the debug output or the immediate window if you redirect all output to the immediate window. In the intermediate Window, you can also evaluate and print variables. To execute Visual Studio command, preface the command with a greater than sign e.g.  ">cmd". This will switch to the command window. Type immed without the ">" will switch back to the immediate Window.



? var is a shortcut for >Debug.Print var. Both print the value of processUpTime in the immediate window.

Code Map 

When you are starting to work on a huge Visual Project, it can be a daunting task to under the big picture and how all the components work together. One feature in Visual Studio that will help you in this area is called Code Map which is available in Visual Studio 2017.

One bad thing about the newer versions is the ability to generate sequence diagrams or UML diagrams are removed in the newer versions of Visual Studio. If you want to use this feature, you can back and install Visual Studio 2013.

Disable IntelliSense

To disable IntelliSense:
  • Go to tools->options
  • In the search box type "intellisense"
  • Select C/C++/Advanced on the left panel
  • Under the Browse/Navigation section in the right panel set the Disable Database to true. 


This will make the build runs faster.  Notice if you disable intelliSense, you cannot do certain things in Visual Studio like  right click on a method and select go to Definition and etc. Some of the options in the right click menu will be grayed out. You can also re-enable IntelliSense after the build is completed.


Disable BSCMAKE

To disable bscmake for a solution having hundreds of projects, the fastest way is to modify the 
Microsoft.CppCommon.targets, which is an XMl file, and remove the target element for bscmake. Comment out any reference to bscmake in the XML file. This file can be found under C:\Program Files (x86)\Microsoft Visual Studio\2017\Common7\IDE\VC\VCTargets  for Visual Studio 2017. Disabling bscmake will also make the build runs faster.


Increase the verbosity of the build and run

Go to tools->Projects and Solutions->Build and Run to set output verbosity and build log file verbosity to Detailed or Diagnostic to see if this could help you find the specific command which causes this issue.



To find out all the projects depending on a particular project:

  1. Find All (CTRL+SHIFT+F)
  2. "Find what:" = Reference.*ReplaceThisTextWithProjectName
  3. Check "Use:" -> "Regular Expression" in the "Find options" section
  4. "Look at these file types:" = "*.*proj* "
  5. "Look in:" = Select a directory/folder on your drive. Don't use "Entire Solution" it won't get to the project file itself. (Don't forget to check "Include sub-folders")