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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics

Public 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 Sub

End 

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

Comments (8)

  1. Regan says:

    Nice post – will surely save me time if i can get the deubgging working on the Windows 2008 64bit CRM server!  (should have stayed in 32bit for dev perhaps….)

  2. Jordna J says:

    Thanks this saved me a lot of time.

  3. The concept of debugging plugins and workflows has been blogged about in the past. There is a lot of

  4. Chris says:

    Thanks, great tip.

    Just one comment, Ctrl-Shift-V is already used for historic paste – which is really useful if u haven’t used it before.

  5. Palani says:

    Is it possible to make  it work for 64 bit?

  6. DotNetWise says:

    haha – try to use that on VS11 lol 🙂

    No macros support anymore!

  7. OSP says:

    Sad that macros were removed in VS 2012, but you can use hotkeys 🙂

    Ctrl+Alt+P Press w (should find first one which in 99% is w3wp) Press Enter OK

  8. Above macro will attach the debugger to all w3wp process running on the machine.

    I have created a macro which could be attached to a specific w3wp process in which your application is running. checkout below link.

    http://www.codeproject.com/…/Macro-to-attach-debugger-to-correct-w3wp-apppool