Attach Asp.Net MVC application to iisexpress in C#

217 Views Asked by At

I developed a visual studio package plugin and today I need to implement the attach to iisexpress in C#.

My plugin builds the project of active document in visual studio editor from a button in context menu, and in the end of the routine, I need to attach it.

I've researched and found it:

System.Diagnostics.Debugger.Launch();

But when this code is executed, Visual Studio freezes and shutdown.

Before this code, I try to find the iisexpress process by:

var IsIisRunning = System.Diagnostics.Process.GetProcessesByName("iisexpress");

if (IsIisRunning.Length == 0)
    return;

So I know the process exists.

Am I forgetting something?

Somebody can help me?

Thanks for your time.

1

There are 1 best solutions below

0
On

I solve the problem using ENVDTE80.Process2 object as follows:

EnvDTE80.Debugger2 dbg2 = (EnvDTE80.Debugger2)dte.Debugger;
EnvDTE80.Transport trans = dbg2.Transports.Item("Default");
EnvDTE80.Engine dbgeng;
dbgeng = trans.Engines.Item("Managed (v4.5, v4.0)");
var proc2 = (EnvDTE80.Process2)dbg2.GetProcesses(trans, Environment.MachineName).Item("iisexpress.exe");
proc2.Attach2(dbgeng);