Saturday 22 August 2009

The 7 Essential Visual Studio Tools

Visual Studio 2008 is the best of the development environments that I've had the pleasure of working with so far. For all that people enjoy putting them down, in my opinion the developers at Microsoft have delivered an excellent product that is both fast and easy to use! (Which isn't to say that it can't be improved - argument vs format string validation is sweet!) This week I'm posting about some of the useful goodies that come with using Visual Studio - things that you technically don't need to know to get the job done but are very handy anyway. I'm listing them in the order that I personally use most frequently:
  1. Find all references. Lists everywhere that a method or variable is used, including the definition. This is really useful when you're trying to work out where a variable is being assigned, or cleared. Right click a method or variable and select Find all references.
  2. Extract method. You've written a bunch of code that gets the job done but it's all inline. It looks horrible, and it's not reusable. Highlight all the code you'd like to break out into a new method, right click and select Extract method. Provide a method name and Visual Studio will create a method for you and even specify the parameters and return value!
  3. The Exceptions window. Press alt + ctrl + e to show this window. Not sure where exactly an exception is being thrown from? Check the Common Language Runtime option in this window and then execute the code.
  4. Call stack window. While debugging, lets you see at a glance the path of method calls that have been made to get you to your current point in the code. Double clicking a method in this window takes you to where the method was called, and let's you see the state of all the local variables. Really handy for debugging. Access through the Debug > Windows menu.
  5. Threads window. While debugging, lets you see how many threads you have executing. Double clicking a thread in this window takes you to its current point of execution in the code. Also accessed through the Debug > Windows menu.
  6. Automatic unit testing. Right click in your code and select Create unit tests... This brings up a dialog that lets you pick which methods to write unit tests for. Visual Studio will then generate a basic unit test for every method you select.
  7. Record/play macro. So you need to perform a repetitive typing operation on your code. Hit shift + ctrl + r to start recording a macro, perform the operation, and hit shift + ctrl + r again. Now every time you press shift + ctrl + p visual studio will perform your typing operation again!

That's probably enough to get a fresh faced youngster up to speed. I'm sure any old hands out there have plenty more to add to this list.

No comments:

Post a Comment