调试期间在 Visual Studio 中自动附加到子进程
当为媒体中心编写插件时,您的插件托管在 ehexthost.exe
中,此 exe 从 ehshell.exe
启动,您无法直接启动它,而是传递一个ehshell.exe 的特殊参数将在单独的进程中启动插件。
当我们调试媒体浏览器时,我发现附加到第二种进程的过程笨重的,我了解 Debugger.Attach 以及一些 特殊注册表我可以使用的条目。
这两种方法都不完全符合我的要求。 我想要的是按 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
另外,我概述了如何在我的博客上进行此操作。
When writing plugins for media center your plugin is hosted in ehexthost.exe
this exe gets launched from ehshell.exe
and you have no way of launching it directly, instead you pass a special param to ehshell.exe
which will launch the plugin in a separate process.
When we are debugging media browser I find the process of attaching to a second process kind of clunky, I know about Debugger.Attach and also of some special registry entries I can use.
Both these methods don't exactly fit my bill. What I want is to press F5 and have my current instance of visual studio attach to the child process automatically. Can this be done?
If there is a plugin for VS that allows me to achieve this functionality I would be happy with it.
EDIT
I ended up going with the following macro:
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
Also, I outlined the process on how to get this going on my blog.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我会使用宏。 我重新定义了 F5 函数以附加到 asp.net 进程,而不是它通常执行的长时间构建/验证。 这对我来说非常有效,而且非常简单。
I would use a macro. I've redefined my F5 function to attach to the asp.net process instead of the long build/validate it usually performs. This works pretty well for me and it's really easy.
对于 VS2012,宏已被删除,但您仍然可以使用标准键盘快捷键快速完成此操作。 例如,要附加到 iisexpress.exe:
Ctrl + Alt + p - 弹出“附加到进程”对话框
i - 跳转到列表中以 i 开头的第一个进程(对我来说,这是 iisexpress.exe)
Enter - 附加
要获得超快速度,您还可以 调试 IIS 时关闭 Visual Studio 附加安全警告。
For VS2012, macros have been dropped, but you can still do it quite quickly with standard keyboard shortcuts. For instance, to attach to iisexpress.exe:
Ctrl + Alt + p - brings up the Attach To Process dialog
i - jumps to the the first process beginning with i in the list (for me this is iisexpress.exe)
Enter - attaches
For super speed, you can also Turn off Visual Studio Attach security warning when debugging IIS.
查看我编写的 VisualStudio 插件,名为 Lazy。
Check out the VisualStudio plugin that I wrote, named Lazy.
我正在外部生成的进程中调试一个 C++ 插件,该插件在启动时抛出异常而崩溃,这对我来说非常有效:
添加免费的 重新附加 Visual Studio 扩展。 要求它在启动之前重新附加到进程名称。 它将弹出一个模式对话框,表示正在等待进程名称启动。
现在启动该进程,Visual Studio 调试器将立即附加,捕获异常并命中断点。
(这也是在媒体插件中,异常通常被 Delphi 上下文中的主机进程捕获并重新抛出,因此我需要在发生这种情况之前中断)。
I was debugging a C++ plugin in an externally spawned process that crashed by throwing an exception at startup and this worked perfectly for me:
Add the free Reattach Extension for Visual Studio. Ask it to reattach to the process name before it is launched. It will pop a modal dialog saying it is waiting for the process name to launch.
Now launch the process and the Visual Studio debugger will attach immediately, catching exceptions and hitting breakpoints.
(This was also in a media plugin, the exception was normally caught and rethrown by the host process in a Delphi context so I needed to break before that happened).
如果您在 Visual Studio 中设置类似的内容,则可以通过按 F5 自动附加到进程:
http://vvcap.net/db/ujYL7zeN_n_RgeprqCSM.htp
注意:有“命令”填写为可执行文件名,“Attach”必须为“yes”
You can automatically attach to a process by pressing F5, if you setup something like that in visual studio:
http://vvcap.net/db/ujYL7zeN_n_RgeprqCSM.htp
notice: There's "Command" filled up as an executable name, and "Attach" must be "yes"