ASP.NET Hosting

Archives

Archives / 2006 / April
  • Attach to Visual Studio's Development Web Server easily using a macro

    Something I have to do frequently is attaching to a running web application for debugging purposes. I don't always start my web applications in debug mode, but I often need to attach at some point when doing some testing.
    Unfortunately, there is no easy way to do this from Visual Studio. We have to attach to the server process "by hand". After some time doing this, you'll find it a bit boring...
    Here is a quick-n-dirty solution. It's a simple macro that attaches to the first web server process it finds. Just copy the code below to your macros using the Macro IDE (Tools | Macros | Macro IDE...).
    Once you have the macro, you can:

    • add a button to a toolbar by right-clicking on the toolbars, then "Customize... | Commands | Macros" and drag & drop the command on the toolbar of your choice
    • map a shortcut key to it using "Tools | Options | Environment | Keyboard" and search for the AttachToFirstDevWebServer
    Warning 1: this code attaches to the first server it finds, not necessarily the right one. Unfortunately, there is no way to find the correct web server as the processes do not provide information such as a port number or other useful information.
    Warning 2: the code searches for Visual Studio 2005's integrated Development Web Server. To attach to IIS instead (from VS 2003 for example), you'll have to adapt the code to attach to aspnet_wp.exe.

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

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

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

    Update: you may have to replace "webdev.webserver.exe" by "webdev.webserver2.exe"

  • MVP again in 2006

    I'm not the first of the April gang to announce my nomination as an MVP for one more year, but count me in for a third year.