Visual Studio: configure debug to attach to process

Go To


I'm using Visual Studio 2008; is it possible to configure a project debugging options to automatically attach to a process with a certain name when hitting F5?

Edit: actual macro, specifying to attach to managed code:

Sub AttachToMyProcess()
        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("Managed")
        Dim proc2 As EnvDTE80.Process2 = dbg2.GetProcesses(trans, "MyMachine").Item("MyProcess")
    Catch ex As System.Exception
    End Try
End Sub 
2009-06-16 07:59
by Paolo Tedesco
How would you want it to behave if there were two instances running - Rowland Shaw 2009-06-16 08:09
In my particular case, I'm sure that there will be only one instance running. In general I don't know, maybe it might show a dialogue in case of ambiguity - Paolo Tedesco 2009-06-16 08:36


It is possible. You can write a macro like this

    For Each proc As EnvDTE.Process In DTE.Debugger.LocalProcesses
        If proc.Name.IndexOf("processname") <> -1 Then
        End If

And then change VS key bindings to execute this macro when F5 is pressed

2009-06-16 09:27
by Juozas Kontvainis
+1, prety nice and usefull macr - TcKs 2009-06-16 10:45


Try pressing CTRL + ALT + P. I suppose you could remap Debug.AttachtoProcess if you really wanted to.

2009-06-16 08:04
by RichardOD


I have written and add-in for this, you may want to try it out.

2009-06-29 08:48
by Pablo Retyk