Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In VS2008, is there a way to automatically "Attach to Process"?

I'm working on a solution that has three projects, all of which run when I start debugging. It gets annoying because if I want to debug an aspect of a particular project that isn't my startup project, I've got to attach the process every time.

Is there any way to have the debugger automatically attach to all projects?

Thanks for your help :)

Cheers

Iain

like image 893
Iain Fraser Avatar asked Dec 08 '09 09:12

Iain Fraser


2 Answers

Why don't you simply set all 3 projects as your startup projects? This way you won't need to attach at all?

Simply go to the properties for you solution and select 'Multiple startup projects'.

like image 76
Jaco Pretorius Avatar answered Nov 15 '22 09:11

Jaco Pretorius


Not quite as elegant as Jaco's answer (never realised you could have multiple startup projects), but may be quite useful. I have a VS macro:

    Function AttachToProcess(ByVal procname As String, ByVal quiet As Boolean) As Boolean
    Dim attached As Boolean = False
    Dim proc2 As EnvDTE80.Process2

    ' Attaching natively, from http://blogs.msdn.com/jimgries/archive/2005/11/30/498264.aspx '
    Dim dbg2 As EnvDTE80.Debugger2 = DTE.Debugger
    Dim trans As EnvDTE80.Transport = dbg2.Transports.Item("Default")
    Dim dbgeng(1) As EnvDTE80.Engine
    dbgeng(0) = trans.Engines.Item("Native")

    For Each proc2 In DTE.Debugger.LocalProcesses
        If (proc2.Name.Contains(procname)) Then
            proc2.Attach2(dbgeng)
            attached = True
            Exit For
        End If
    Next

    If (attached = False And quiet = False) Then
        MsgBox(procname + " is not running")
    End If
    Return attached
End Function

Sub AttachToMyProcess1()
    AttachToProcess("MyProcess1.exe", True)
End Sub
Sub AttachToMyProcess2()
    AttachToProcess("MyProcess2.exe", True)
End Sub

I then attach the AttachToMyProcessX() macros to keyboard shortcuts. This has the advantage that you can attach to a process retrospectively: hitting Ctrl-F5 then attaching is often quicker than starting with F5.

like image 39
the_mandrill Avatar answered Nov 15 '22 07:11

the_mandrill