Friday 21 September 2007

Visual Studio Auto-Attach Macro

Although using the debugger to attach to your running code to inspect things can be considered "a bad thing" in some circumstances (i.e.: why aren't you using Debug.Assert() to enforce the internal state you are examining with the debugger? why aren't you using unit tests to enforce the exit state you are examining with the debugger?); sometimes you just got to do it. Well I do at least.

For ASP.NET development (IIS, Development Server, Cassini, or whatever) this can be a pain. You need to:
  1. Open the "Attach to..." window.
  2. Find the process (web server) you are interested in.
  3. Attach, wait and close the window.
As an alternative, I've been using a small macro to do these three steps and bound it to a little icon in the toolbar. Very easy: click the gears icon (my personal choice) and you're attached. Click the detach icon (default) and you're out of debug mode.



Of course you will need to alter the name of the process to look for depending on your web server (IIS 5 will typically need "aspnet_wp.exe", IIS 6 depends on the process mode you choose to run in).

I must apologise, the idea for this macro was taken from a source I can't locate anymore. The code is slightly modified, but the idea is the same.

' This subroutine attaches to the first Development Web Server found.
Sub AttachToFirstDevWebServer()
Dim process As EnvDTE.Process

For Each process In DTE.Debugger.LocalProcesses
If (Path.GetFileName(process.Name) = "UltiDevCassinWebServer2a.exe") Then
process.Attach()
Exit Sub
End If
Next

MsgBox("No ASP.NET Development Server found")
End Sub

Tuesday 18 September 2007

It just made sense at the time...



After several weeks of ignoring Google Reader, I was playing catchup, and this one stuck a chord. It's so easy to pay out on advertising or marketing; but this one just seems right.