Tuesday, October 29, 2013

Debugging in Visual Studio

Using the Debugger - The Basics

Before getting into tips and tricks you can use in the Visual Studio debugger, let's cover the basics of using the debugger in the first place.  When you've written a piece of code and you would like to see the code in action, you can use the debugger to look at your code.  This article will look at how to use the debugger in an ASP.NET web page.   

Setting a Start Page

Since we are using an ASP.NET web application, you will need to ensure you have a start page set before attempting to debug.  For this example we will use Default.aspx.  Right click your start page in the Solution Explorer and select "Set as Start Page". 
 

Ready to Debug

Believe it or not, with those few instructions you are now ready to launch your debugger.  With what we've done so far, the debugger will only stop on an error such as the one we've purposefully added to our code for this example.  It is circled below.  To launch the debugger, click the "Green Play Button" on your Visual Studio toolbar.

Your browser will now launch attempting to display your start page. 

Checking Out Your Error

As I've already mentioned, there is an error our debugger will hit.  You of course don't have to put errors in your code on purpose, as a matter of fact I recommend against it.  This error was added to show you that Visual Studio will stop on errors it finds while debugging as the screenshot below proves.



Escape Plan

To break out of Debug Mode just click the "Blue Stop Button" on your Visual Studio toolbar shown in the image above.


Monday, October 28, 2013

Refactoring in Visual Studio, Part 1

Rename

Did you know that there's an easier way to rename properties, methods, variables, etc? This lovely little gem works across all files in the current solution too, so it does more than just a single method or file at a time. Right-click on the item you want to rename and select "Refactor-->Rename".


Type in the new name and hit the OK button.
  


Review the preview if necessary, and click the Apply button when you're ready to process the rename.


 Your code now reflects the changes.