Last week I was doing a lot of ASP.NET debugging – tracing through Microsoft AJAX web service calls and was getting a little frustrated of the time lag for starting a site in debug mode; I remembered a Visual Studio macro for attaching to the worker process and that I had rewritten in a couple of years ago to attach to multiple worker processes, in case you were running multiple sites (i.e. a web services layer and an application layer) on either Windows XP (aspnet_wp.exe) or Windows Server 2003 (w3wp.exe). Below is the source for the macro – I've tested it on Visual Studio Orcas Beta 1.
Imports System
Imports EnvDTE80
Imports System.Diagnostics
Public Module AttachToWebServer
Public Sub AttachToWebServer()
Dim AspNetWp As String = "aspnet_wp.exe"
Dim W3WP As String = "w3wp.exe"
If Not (AttachToProcess(AspNetWp)) Then
If Not AttachToProcess(W3WP) Then
System.Windows.Forms.MessageBox.Show(String.Format("Process {0} or {1} Cannot Be Found", AspNetWp, W3WP), "Attach To Web Server Macro")
End If
End If
End Sub
Public Function AttachToProcess(ByVal ProcessName As String) As Boolean
Dim Processes As EnvDTE.Processes = DTE.Debugger.LocalProcesses
Dim Process As EnvDTE.Process
Dim ProcessFound As Boolean = False
For Each Process In Processes
If (Process.Name.Substring(Process.Name.LastIndexOf("\") + 1) = ProcessName) Then
Process.Attach()
ProcessFound = True
End If
Next
AttachToProcess = ProcessFound
End Function
End Module