Freigeben über


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

Comments

  • Anonymous
    October 30, 2008
    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....)

  • Anonymous
    November 02, 2008
    Thanks this saved me a lot of time.

  • Anonymous
    May 08, 2009
    The concept of debugging plugins and workflows has been blogged about in the past. There is a lot of

  • Anonymous
    March 08, 2010
    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.

  • Anonymous
    October 14, 2010
    Is it possible to make  it work for 64 bit?

  • Anonymous
    March 23, 2012
    haha - try to use that on VS11 lol :) No macros support anymore!

  • Anonymous
    January 29, 2013
    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

  • Anonymous
    February 15, 2013
    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. www.codeproject.com/.../Macro-to-attach-debugger-to-correct-w3wp-apppool