4

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()
    Try
        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")
        proc2.Attach2(dbgeng)
    Catch ex As System.Exception
        MsgBox(ex.Message)
    End Try
End Sub 
2
  • How would you want it to behave if there were two instances running? Jun 16, 2009 at 8: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? Jun 16, 2009 at 8:36

3 Answers 3

12

It is possible. You can write a macro like this

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

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

0
2

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

1

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

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.