Visual Studio Add-In To Automatically Attach to Development Server
Asked Answered
T

3

8

Is anyone aware of a Visual Studio 2010 Add-In that will automatically allow you to attach to a running instance of the ASP.Net Development Server? And if there is more than one currently running, display a quick dialog that lets you choose from a list of just the ASP.Net Development Servers that are running?

Why do I want this? <-- feel free to skip this part.

The way I usually develop / debug web applications is to launch a browser and navigate through the application until I get to the page I want (could be many pages deep.) I don't want to have the debugger attached through these steps for various reasons (it is slower than not having it attached, extraneous break-points may be hit, I may have break when "thrown" turned on and not want to break earlier in the app when handled errors are thrown, etc...)

I navigate to the page I want, then use the Visual Studio menus to Debug > Attach to Process, and then from within the Attach to Process dialog, I have to scroll all the way down (pages and pages and pages of processes) until I find the WebDev.WebServer40.EXE process I want and choose that.

Doing this makes me take my hands off the keyboard and use a mouse (something I generally try to avoid.)

And doing this seems needlessly repetitive since, if I am debugging an ASP.Net Web Application, I always want to attach to an instance of the WebDev.WebServer40.exe.

Timeserver answered 30/9, 2011 at 14:24 Comment(7)
Unless you want to attach to an instance of WebDev.WebServer20.exe, w3wp.exe, iisexpress.exe, or aspnet_wp.exe.Roundel
I'd be happy if the add-in filtered to those choices. (or, even better, was smart enough to read the project settings and know automatically where that project is running.)Timeserver
I didn't see the part about the "prompt" but it would be pretty easy to add this feature into my answer. You'd just have to look up the commands to accomplish the prompt etc but all the information you need is out there!Anthologize
Your answer is great, Allen. Marked as Accepted. Thanks!Timeserver
You can absolutely do this from keyboard, hit Ctrl+Alt+P, then Alt+V (needed only if focus is not not on the list already) and start typing webdev..... the hit Alt+A and voila! However I'm with you, automating this is the way to go if you do attach often.Neilla
What would be best is to have a command that would to "Attach to the same proces you were last attached" which you can absolutely do as an addin (actually I think I'm gonna do it for myself) and attach a global key chord to it via Tools -> Options -> Environemnt -> Keyboard, yeah that will be really nice :)Neilla
Possible duplicate of Visual Studio - Attach to process shortcutUnregenerate
A
7

I prefer to do the exact same thing and it IS possible to bind it all to a keystroke with a macro.

Goto Tools > Macros > Macro IDE

Add a new module and use this code (the funky comments are for syntax highlighting)

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a
Imports EnvDTE100
Imports System.Diagnostics
Imports System.Collections.Generic

Public Module AttachingModule
    Sub AttachToAspNET()
        Try
            Dim process As EnvDTE.Process

            Dim listProcess As New List(Of String)
            '' // uncomment the processes that you'd like to attach to.  I only attach to cassini
            '' // listProcess.Add("aspnet_wp.exe")
            '' // listProcess.Add("w3wp.exe")
            listProcess.Add("webdev.webserver")

            For Each process In DTE.Debugger.LocalProcesses
                For Each procname As String In listProcess
                    If process.Name.ToLower.IndexOf(procname) <> -1 Then
                        process.Attach()
                    End If
                Next
            Next

        Catch ex As System.Exception
            MsgBox(ex.Message)
        End Try
    End Sub

End Module

Click on File > Close and return

Click on Tools > Options

Click on Environment > Keyboard

I put the macro in MyMacros, so I look for "Macros.MyMacros.AttachingModule.AttachToAspNET" in the "Show Commands Containing" textbox".

I prefer to use Ctrl+Alt+D but put whatever you want in the "Press Shortcut Keys" textbox and click Assign, then OK

Now all you have to do is hit Ctrl+Alt+D to attach to all cassini instances.

I've seen various versions of this around the internets and this was the most recent I found. I had to modify that slightly to remove the extra web processes and to drop the .exe from WebDev.WebServer.exe, so that it would debug .net 4.0 instances of cassini.

Anthologize answered 27/1, 2012 at 17:45 Comment(3)
The sad part is that macros have been removed from VS2012 :(Neilla
Whaaat? I finally setup 2012 today. That's disappointing :-/Anthologize
This is awesome, I don't know why I waited so long to look for this question and response. On our SharePoint dev server (where VS is installed) we often have 6 - 10 w3wp processes and I have to attach to all of them every time I debug. This is great....Sailing
P
4

I don't know of any such add-in but you can more easily attach to the process using shortcut keys and pressing 'W' to scroll to the WebDev process.

Ctrl+Alt+P - Attach to Process
(process window now has focus)
Press W, which jumps to processes starting with W
Press Enter to attach

Not an addin but you can do it without touching the mouse.

Philia answered 30/9, 2011 at 14:59 Comment(1)
Thanks for sharing the Attach to Process shortcut - for some reason it's hidden in the Debug menu shortcut description.Cellular
B
1

Check this answer out: Attach To Process in 2012

This is a simple plugin that gives shortcuts to attaching to nunit agent, IIS and IIS Express. Its pure convenience as compared to Ctrl-Alt-P, but it is convenient.

Direct link to the plugin here

Balfour answered 18/12, 2012 at 8:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.