Visual studio 2012 add-in - how to attach debugger to a process

mut*_*tex 5 .net c# visual-studio-addins visual-studio-2012

I have a scenario where when I start debugging a silverlight OOB project in visual studio the debugger attaches to that automatically, but it doesn't attach to the iisexpress process which is running the web service that the silverlight application connects to. It does start iisexpress but doesn't attach to it automatically. I have to manually go to Debug->Attach to process, find iisexpress and attach to it to debug both client and serverside code.

Since VS2012 removed macros I can't use that to automatically attach, so I'm trying to create a simple add-in to do it instead.

我坚持如何依附于这个过程.我尝试了以下方法,它们都在正确的时间触发并找到iisexpress进程,但是当尝试连接到它时,所有3个都给出了异常.谁能建议我怎么做?

private void DebuggerEventsOnOnEnterRunMode(dbgEventReason reason)
{
    if (reason == dbgEventReason.dbgEventReasonLaunchProgram)
    {
        foreach (Process process in _applicationObject.Debugger.LocalProcesses)
        {
            var nameparts = process.Name.Split(Path.DirectorySeparatorChar);
            string name = nameparts[nameparts.Length - 1];
            if (name.Contains("iisexpress"))
                    process.Attach();  
                    // also tried: _applicationObject.ExecuteCommand("Debug.AttachToProcess", process.Name);
                    // and: _applicationObject.ExecuteCommand("Debug.AttachToProcess", name);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

Ron*_*B.I 4

适用于 VS 2010 和 VS 2012:

解决方案->右键->设置启动项目->多个启动项目

选择您的 2 个项目,然后在操作下将其设置为Start,而不是(对于第二个项目)可能的Start Without Debugging