代码之家  ›  专栏  ›  技术社区  ›  Iain Fraser

在VS2008中,是否有自动“附加到进程”的方法?

  •  6
  • Iain Fraser  · 技术社区  · 16 年前

    我正在研究一个有三个项目的解决方案,所有项目都在我开始调试时运行。这很烦人,因为如果我想调试一个不是我的启动项目的特定项目的某个方面,我必须每次都附加这个过程。

    有没有办法让调试器自动附加到所有项目上?

    感谢您的帮助:)

    干杯

    伊恩

    2 回复  |  直到 16 年前
        1
  •  18
  •   Jaco Pretorius    16 年前

    为什么不简单地将所有3个项目都设置为启动项目?这样你就不需要连接了?

    只需转到解决方案的属性并选择“多个启动项目”。

        2
  •  3
  •   the_mandrill    16 年前

    不像Jaco的回答那么优雅(从未意识到你可能有多个创业项目),但可能非常有用。我有一个vs宏:

        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
    

    然后我附加 AttachToMyProcessX() 宏到键盘快捷键。这有一个优点,您可以回顾性地附加到一个进程:先按ctrl-f5,然后再按attaching通常比从f5开始要快。