【发布时间】:2009-01-08 00:30:30
【问题描述】:
为媒体中心编写插件时,您的插件托管在 ehexthost.exe 中,此 exe 从 ehshell.exe 启动,您无法直接启动它,而是将特殊参数传递给 ehshell.exe,它将启动插件在一个单独的过程中。
当我们调试 media browser 时,我发现附加到第二个进程的过程有点笨拙,我知道 Debugger.Attach 以及一些我可以使用的 special registry 条目。
这两种方法都不完全符合我的要求。我想要的是按 F5 并让我当前的 Visual Studio 实例自动附加到子进程。这可以做到吗?
如果有一个 VS 插件可以让我实现这个功能,我会很高兴的。
编辑
我最终选择了以下宏:
Public Sub CompileRunAndAttachToEhExtHost()
DTE.Solution.SolutionBuild.Build(True)
DTE.Solution.SolutionBuild.Debug()
Dim trd As System.Threading.Thread = New System.Threading.Thread(AddressOf AttachToEhExtHost)
trd.Start()
End Sub
Public Sub AttachToEhExtHost()
Dim i As Integer = 0
Do Until i = 50
i = i + 1
Try
For Each proc As EnvDTE.Process In DTE.Debugger.LocalProcesses
If (proc.Name.IndexOf("ehexthost.exe") <> -1) Then
proc.Attach()
Exit Sub
End If
Next
Catch e As Exception
' dont care - stuff may be busy
End Try
Threading.Thread.Sleep(100)
Loop
End Sub
另外,我在我的博客上概述了如何get this going 的过程。
【问题讨论】:
-
新的 Debugger2 接口还有其他方法,codeplex.com/lazy/SourceControl/changeset/view/20095#307770
-
使用Debugger2接口有优势吗?
-
是的,而不是在 DTE.Debugger.LocalProcesses 上循环,您只需获取进程 proc = debugger2.GetProcesses(trans, "").Item(processName)
-
我的 VB 很生锈 - 我得到“名称 'proc' 未声明” - 关于需要修复什么的任何想法?
-
想通了。应该如下: For Each proc As EnvDTE.Process In DTE.Debugger.LocalProcesses
标签: c# .net visual-studio debugging visual-studio-debugging