In case you didn't know, there is a much faster way to debug an ASP.NET application when running IIS than hitting F5. You can directly attach the debugger to the existing w3wp.exe to quickly start your debug session by doing Debug -> Attach to Process -> w3wp.exe. After a while, you start using the "Attach to Process" command very often in a usual day. I created a simple visual studio macro to automatically attach to the ASP.NET process when you need to debug a site. Then you can call the macro with a simple keyboard shortcut. Here is the code:
Option Strict Off
Option Explicit Off
Public Module RecordingModule
Dim dbg2 As EnvDTE80.Debugger2 = DTE.Debugger
Dim trans As EnvDTE80.Transport = dbg2.Transports.Item("Default")
Dim compName As String = WindowsIdentity.GetCurrent().Name
compName = compName.Substring(0, compName.IndexOf("\"))
Dim proc2 As EnvDTE80.Process2 = dbg2.GetProcesses(trans, compName).Item("w3wp.exe")
Catch ex As System.Exception
To create the macro in your Visual Studio, just open the Macro Explorer in Tools->Macro->Macro Explorer, make a new macro and copy paste the code. The only thing you could need to change is "w3wp.exe" or "aspnet_wp.exe" depending on your version. Note that I'm assuming you're working with only one w3wp active at a certain point in time. Those of you who have multiple worker processes running simultaneously should feel free to augment the code for your purposes. (Take a look at this to figure out which w3wp to attach to.)
Creating a keyboard shortcut afterwards is pretty easy:
Go to Tools->Options in Visual Studio. Then just follow those easy steps:
- Click on Environment->Keyboard
- Type AttachToAspNET in the "Show commands containing" textbox.
- Press a keyboard shortcut you want to use. I used Ctrl-Alt-K and it is working fine.
- Click on Assign
Happy coding in 2008!
View this post in Russian :).