addin that tells the Visual Studio to start a program and attach to it

Hi,

Is it possible to write an addin which shows a tool window where I can select a list of programs and tell visual studio to start the selected one and attach to it? I can see the tool window in the automation samples - so I can create a custom one with a list of populated .exes. I can also use .Net API Process class to start the selected one. But how do I tell VS to attach to it?

Thanks
Pawan

[412 byte] By [PawanSingh] at [2007-12-18]
# 1
So I found the following:

EnvDTE.Processes procs = _applicationObject.Debugger.LocalProcesses;
EnvDTE.Process p = procs.Item(0);
p.Attach();

The trouble is procs.Item(object x) takes object as signature. So how do I iterate through all the processes in procs?

Thanks
Pawan

PawanSingh at 2007-9-8 > top of Msdn Tech,Visual Studio,Visual Studio Extensibility...
# 2

When a Item method takes an object (most Item methods in the object model do), it means either you can pass either an integer or string index value to find the item that you are looking for.

Craig

CraigSkibo at 2007-9-8 > top of Msdn Tech,Visual Studio,Visual Studio Extensibility...
# 3
Here is the code I came up with. The problem is that Visual Studio attaches to it - but my breakpoints are never hit. The program ends up executing to completion. I tried p.Break(true) and dte.Debugger.Break(true) - but both of them raise COM exception. It seems like breakpoints are not getting set after attach. Is there any other API I need to call to enable the break points? My break points have been pre-set in Visual Studio. I load my plugin which executes this code and it should attach to my process and hit the break points. It attaches but never hits my break points.

If I attach to my process without this plugin, it works perfectly i.e. VS stops at my breakpoints.

-Pawan

EnvDTE80.DTE2 dte = (EnvDTE80.DTE2)System.Runtime.InteropServices.Marshal.GetActiveObject(
"VisualStudio.DTE.8.0");
Processes procs = dte.Debugger.LocalProcesses;
bool found = false;
foreach (EnvDTE80.Process2 p in procs) {
if (p.Name != null && p.Name.Length > 0) {
string comName = p.Name;
try {
comName = Path.GetFileName(comName);
}
catch { }
if (comName.Trim().ToLower() == "myprog.exe") {
p.Attach2("Managed");
dte.Debugger.CurrentProcess = p;
found = true;
break;
}
}
}

PawanSingh at 2007-9-8 > top of Msdn Tech,Visual Studio,Visual Studio Extensibility...
# 4

You have asked his question again in a newer post, closing this one.

Craig

CraigSkibo at 2007-9-8 > top of Msdn Tech,Visual Studio,Visual Studio Extensibility...

Visual Studio

Site Classified