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:
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:
Now let’s add keyboard shortcut for our macro from Tools > Options and Environment > Keyboard:
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!