blogs.conchango.com

welcome to the conchango blogging site
Welcome to blogs.conchango.com Sign in | Join | Help
in Search

Howard van Rooijen's Blog

Attach to Web Server Macro for Visual Studio

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

Published 24 June 2007 14:58 by howard.vanrooijen

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

merrick.chaffer said:

Nice one Howard. This is real useful for the current WCF - WEB app debugging we're doing at the moment.

July 13, 2007 15:15
 

Darius Collins said:

Cool Howard. Although we are building a Windows app, our WCF services are hosted inside IIS, so this works just as well. As well as a hot key, I've added a nice big button called "Attach to Webserver" (with accompanying smiley face) to my debug toolbar, so that I don't forget to attach before starting on a lengthy debug session - avoids the dreadful disappointment of having pains-takingly set up a particular scenario, and then wonding why my break points aren't hit in the server code - then having to start all over again. Cheers!
September 20, 2007 16:29
 

Rob Grigg said:

Will this work (with the namespace adjustment) for VS2003?
October 19, 2007 12:02
 

howard.vanrooijen said:

Yes. It was originally written for VS 2003

October 19, 2007 12:08
 

Jason Finch said:

Really useful macro thanks!
November 29, 2007 02:45
 

DotNetKicks.com said:

You've been kicked (a good thing) - Trackback from DotNetKicks.com

December 8, 2007 14:45
 

Techies blog » Blog Archive » SharePoint távoli hibakeresés makró said:

May 22, 2008 22:10
 

Jasper said:

Fantastic! Wanted something like this for ages, never got around to doing it.

July 3, 2008 01:45

Leave a Comment

(required) 
(optional)
(required) 
Submit
Powered by Community Server (Personal Edition), by Telligent Systems