views:

142

answers:

2

Hi there,

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

+17  A: 

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'.

Jaco Pretorius
Hey, would you look at that. Thanks Jaco, I didn't realise you could do that. Nice work :)
Iain Fraser
I didnt know that either! Cool, now to figure out where I need it ;p
leppie
+2  A: 

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.

the_mandrill
Wow man, that's hardcore! Well done :)
Iain Fraser
I aim to please...
the_mandrill