Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attaching to a child process automatically in Visual Studio during Debugging

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.

like image 219
Sam Saffron Avatar asked Jan 08 '09 00:01

Sam Saffron


People also ask

How do I Debug code with attach process in Visual Studio?

You can attach the Visual Studio debugger to a running process on a local or remote computer. After the process is running, select Debug > Attach to Process or press Ctrl+Alt+p in Visual Studio, and use the Attach to Process dialog to attach the debugger to the process.

How do I attach a process in Visual Studio 2017 for debugging?

In visual studio click Tools | Attach to process. Then select appropriate service. On later versions of Visual Studio it's under Debug | Attach to process (instead of under Tools menu).

How do I Debug multiple processes in Visual Studio?

To change the startup project, in Solution Explorer, right-click a different project and select Set as StartUp Project. To start debugging a project from Solution Explorer without making it the startup project, right-click the project and select Debug > Start new instance or Step into new instance.

How do I skip the code while debugging in Visual Studio?

You can also click on the line you want to skip to and hit Ctrl+F10 (Run to Cursor).


1 Answers

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.

    For Each process In DTE.Debugger.LocalProcesses         If (process.Name.IndexOf("aspnet_wp.exe") <> -1) Then             process.Attach()             Exit Sub         End If     Next 
like image 63
Jab Avatar answered Oct 08 '22 18:10

Jab