c# - 在调试期间在 Visual Studio 中自动附加到子进程

标签 c# .net visual-studio debugging visual-studio-debugging

为媒体中心编写插件时,您的插件托管在 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 的过程在我的博客上。

最佳答案

我会使用宏。我重新定义了我的 F5 函数以附加到 asp.net 进程,而不是它通常执行的长时间构建/验证。这对我来说效果很好,而且非常简单。

    For Each process In DTE.Debugger.LocalProcesses
        If (process.Name.IndexOf("aspnet_wp.exe") <> -1) Then
            process.Attach()
            Exit Sub
        End If
    Next

关于c# - 在调试期间在 Visual Studio 中自动附加到子进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/422768/

相关文章:

单元测试期间的 C# 扩展方法奇怪

c++ - 如何将此 VC++ 6 代码转换为 VC++ 2008?

c# - 创建 Xml 属性 json :Array using XElement and XNamespace C# classes

c# - Webdriver - Webdriver MoveToElement 在 IE 和 Firefox 中无法获取文本工具提示

C# 使用 JSON.Net 解析 JSON 数字属性

c# - 无需调试的立即窗口

.net - 用于区分大小写的字符串比较的 Resharper 模式

visual-studio - Azure PaaS 和 ALM - 如何通过单击发布处理分支?

c# - 更改 PictureBox 的位置

c# - 单元测试HQL查询