Posts Tagged ‘Visual Studio’

Shortcuts for code snippets that I use everyday coding

I note down here to share my daily-used code snippets in Visual Studio 2010.
Each entry is applied by typing the snippet’s shortcut followed by `tab` key. Then, you can `tab` to navigate around the change-able values of the snippet.

  1. prop
    New property in short mode, i.e. { get; set;  }
  2. propfull
    New property in full mode
  3. for
    Insert simple for loop
  4. (More to be updated when available)



List of hotfixes for Visual Studio 2010

Microsoft doesn’t make an easy-to-find list of hotfixes for Visual Studio 2010 as discussed here. From that useful talk, the list are stored here.

Here is the hotfixes that I found useful for my own use.

[The IDE]

  1. KB2268081 – QFE: Find and Replace Dialog grows in width with each invocation
  2. Cut or Copy displays ‘insufficient memory’ error in Visual Studio 2010
  3. KB2345133 – Fix for scrolling unnecessarily in VS context menus
  4. KB2275326 – The Visual Studio 2010 development environment crashes on shutdown


  1. KB2402815 – Source control does not flag conflict during cherry pick merge

(to be updated)


Collected Visual Studio tips

Here I list out the “cool” Visual Studio tips that considered to make big changes in my working style with this IDE.

  1. Generate the sequence diagram (referenced here)

(to be continued)

How to get unit-testing code-coverage run from command line?

For efficiency & quickness, I prefer to run unit test & get the code coverage from the command line – this helps me spare the Visual Studio IDE to do other tasks. For me, running testing related tasks in the IDE is very slow, especially if you are working in a big project.

Here’s how to do it

1) Launch VS command prompt or change to the VS location which contains the tools, e.g. %ProgramFiles%\Microsoft Visual Studio 10.0\Team Tools\Performance Tools.

2) Instrument the product dlls using
vsinstr /coverage “Path\To\You\TestedAssembly.dll”

3) Start coverage monitor by running the command
vsperfcmd /start:coverage /output:”Path\Of\Report.code-coverage”

4) Run your tests which are testing the functionality of Path\To\You\TestedAssembly.dll
(manual or automated, doesnt matter)

5) Stop the coverage monitor by running the command
vsperfcmd /shutdown

Here’s the details

The first main step to collecting code coverage information is to instrument the assemblies that you are interested it. Instrumentation will insert code into the assemblies so that when they are run, code coverage information will be collected. You can instrument both managed and native dll files, exe files and assemblies. The tool that you use to instrument is called VsInstr.exe and it is found in the following directory

Microsoft Visual Studio 8\Team Tools\Performance Tools

Instrumenting the assembly is done by passing the –coverage option to the VsInstr.exe tool:

vsinstr –coverage MyAssembly.exe

When you instrument the assembly you are modifying it permanently, so the VsInstr tool automatically makes a backup of the file you instrument. In this case the backup will be called MyAssembly.orig.exe.

The next step in collecting code coverage information is to make sure that the collection monitor is running so that our collected coverage data gets written somewhere. The coverage monitor is called VsPerfMon.exe and is located in the same location as VsInstr.exe was located. To start it up for code coverage collection just use the following command:

start vsperfmon –coverage –output:mytestrun.coverage

Now the command shell will be running your monitor, waiting for some data to collect and write to the output file. Now is the time where you run your test suites or exercise your instrumented code in whatever manner you want to collect coverage information for. The command window will wait until the instrumented code has exited before it will close down and create the coverage file. Once it has, you will now have a code coverage file called mytestrun.coverage that details what code you exercised in your instrumented assembly while the monitor was running. You can open this file directly from Visual Studio to see a code coverage results window that will give you a breakdown of what percent of the code in your instrumented assembly was covered.


  1. (the idea)
    TN_1214: Gathering code coverage information from the command line
  2. (the details)
    Code coverage of generic unit testing

Visual Studio Find/Replace Regular Expression Usage – CodeProject

If you ever work with auto-generated code, you would get tons of warnings like me. In those cases, search and replace a pattern is in-the-need, and regular-expression is quite handy at those situations!

For my situation, I need to covert the line in the form as below:

And change it to be:

The problem is I got hundreds of lines in this need-to-changed form (generated by the Unit Test Creating feature of VS). So, I use Replace All as below screenshot and get all things ordered! Oh yeah!


Here’s a good review about using the regular expression!

Visual Studio Find/Replace Regular Expression Usage – CodeProject.

Have fun! Life has lots of interesting stuff to learn & we can learn!

How to show Output Window when starting ‘Build’ in Visual Studio?


First make it “Tabbed Document”, then hide it, then go to Tools->Options->Project and Solutions->General->Show Output Windows when Build start


Helpful & Frequently-used hot keys in Visual Studio IDE

This is my list of hot keys which I often used – the list is gradually updated. Hope you can find it useful.

  1. Select a text and Ctrl-F3 Search for selected text. Very useful when you browse the codes, meet some references (method, properties, variable, …) that you want to quickly see other locations it appears.