Attaching debugger to w3wp.exe using nice and easy keyboard shortcut

How many times have you done some web development and used following method to attach your Visual Studio Debugger to w3wp.exe (a.k.a. Debug > Attach to Process –method):
image 

And then you scroll the long list and find your w3wp.exe and press attach:
VSDebugger

I’ll bet that you have done that a lot :-) At least I have.

Let’s create macro that does that very same thing but so that you don’t have to take your fingers of the keyboard.
First open up Macro Explorer (using View > Other windows > Macro Explorer or just hit Alt-F8). Then open up example AttachToCalc macro under Samples > VSDebugger:
image 

Right click and select edit:
image

Copy contents of that and create new macro under My Macros:
image 

And give it a name MyVSDebugger. Then paste the source code to it. Then modify the process name from calc.exe to w3wp.exe and remove the Exit For. You should have something like this left:

 123456789101112131415161718192021222324252627
 Imports SystemImports EnvDTEImports EnvDTE80Imports EnvDTE90Imports System.DiagnosticsPublic Module MyVSDebugger  ' This subroutine attaches to w3wp.exe:  Sub AttachToW3WP()    Dim attached As Boolean = False    Dim proc As EnvDTE.Process    For Each proc In DTE.Debugger.LocalProcesses      If (Right(proc.Name, 8) = "w3wp.exe") Then        proc.Attach()        attached = True      End If    Next    If attached = False Then      MsgBox("Couldn't find w3wp.exe")    End If  End SubEnd 

Now you should have this kind of view at the Macro Explorer:

image

Now let’s add keyboard shortcut for our macro from Tools > Options and Environment > Keyboard:

image

Just find your new macro and set focus to Press shortcut keys field and press your favorite keyboard shortcut and press Assign and then press OK. NOTE: You might have another command already using that combination but you can override it if you like.

Now we’re ready to use that. If you want to build your solution you can Ctrl-Shift-B and if you want to attach to w3wp.exe you’ll just press Ctrl-Shift-V. This is extremely handy if you have Post-Build event nicely set.

Anyways... Happy hacking!

J