Dennis van der Stelt

I care about technology; I care about users more

Community

Email Notifications

News

  • Addicted to Refactor! Pro
    <div class="sideNavItems">

I read...

I Use...

Tags

Recent Posts

Archives

Blog Subscription Form

  • Email Notifications
    Go

Attach to debugger script and shortcut

I got sick of manually attaching to the webserver (either aspnet_wp.exe on WinXP or w3wp.exe on Win2003 or later). You can have a macro for that, incl. a shortcut key. I got this from somewhere on the web, but forgot where. If I find out, I’ll of course post it here. But I constantly have to search my sent items in Outlook for this bit of script when I tell someone about this. So here it’s on my weblog.

  • Press ALT-F11 (Macro IDE)
    A new Windows pops up
  • In the Project Explorer on the left, choose "Add new Item"
  • Choose a Module and name it "AttachToWebServer"
  • Paste the code below (and overwrite anything that was already there)
  • Close this Window
  • In Visual Studio, do "Tools" -> "Options" -> "Environment" -> "Keyboard"
  • In the textbox for "Show commands containing" type "AttachToWebServer"
  • In the "Press shortcut keys" press ALT F10
    It's currently bound to something you're not using anyway ;-)
  • Press "Assign" and "Ok"

Now go to your web application project and press ALT+F10 and you're in debug mode, attached to the webserver. Press F5 in your browser (of course in the correct website) and you're done!

Here’s the code:

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

Comments

Thomas Freudenberg said:

"I got this from somewhere on the web, but forgot where. If I find out, I’ll of course post it here."

I guess it was me, since I referred to you then ;)

thomasfreudenberg.com/.../Auto_2D00_attaching-to-aspnet_5F00_wp.exe.aspx

# March 10, 2009 4:39 PM

Dennis van der Stelt said:

@Thomas : lol, and from you to Roy Osherove, to Kevin... I'll provide links to everyone! :)

# March 10, 2009 9:40 PM

Trevor Benedict said:

Look @ EnvDTE80.Transport to specify the

Dim dbg2 As EnvDTE80.Debugger2 = DTE.Debugger

   Dim trans As EnvDTE80.Transport = dbg2.Transports.Item("Default")

   Dim dbgeng(2) As EnvDTE80.Engine

   dbgeng(0) = trans.Engines.Item("Managed")

   dbgeng(1) = trans.Engines.Item("Native")

   Dim proc2 As EnvDTE80.Process2 = dbg2.GetProcesses(trans, "DELL-09").Item("WebDev.WebServer.EXE")

   proc2.Attach2(dbgeng)

# March 13, 2009 1:41 AM

gOODiDEA.NET said:

.NET NP .NET Profiler – a tool is designed to assist in troubleshooting issues such as slow performance

# March 13, 2009 2:17 AM

gOODiDEA said:

.NETNP.NETProfiler–atoolisdesignedtoassistintroubleshootingissuessuchasslowperf...

# March 13, 2009 2:18 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Please add 6 and 8 and type the answer here: