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.
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).
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.
Check out the VisualStudio plugin that I wrote, named Lazy.
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.
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"