views:

1976

answers:

3

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 seperate 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 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.

A: 

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"

galets
Thanks! But this trick does not work for C# projects you do not have an option like that in the debug list, only the option to start an external program
Sam Saffron
I think i know what you mean... you can create a "dummy" c++ project and add it to your solution. As long as it attaches top a correct executable, you are good to debug.
galets
+5  A: 

Please look the plugin I wrote.

pablito
+1 will try it out and see how i go
Sam Saffron
thanks, I wrote it when I have a similar scenario like yours, my process was invoked by other process and I needed to debug the initialization of my process so I needed to attach it as soon as it starts. If you have any questions let me know. "It works in my machine"
pablito
nice plugin - thanks!
Lost Hobbit
+10  A: 

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
Jab
Thanks for the cool trick!
Gavin Miller
Thanks man, I used this to attach to WebDev.WebServer and IE when I hit F4
Allen