public static void DebugAttachToNode(int subjectProcessId, int port) { // Register COM message filter on this thread to enforce a call retry policy // should our COM calls into the DTE (in another apartment) be rejected. using (var mf = new ResilientMessageFilterScope()) { EnvDTE.DTE dte = GetAllDTEs().FirstOrDefault(x => ProcessExtensions.IsProcessAAncestorOfProcessB(x.Key, Process.GetCurrentProcess().Id)).Value; if (dte == null) { dte = GetAllDTEs().FirstOrDefault().Value; } IEnumerable <EnvDTE.Process> processes = dte.Debugger.LocalProcesses.OfType <EnvDTE.Process>(); EnvDTE.Process process = processes.SingleOrDefault(x => x.ProcessID == subjectProcessId); if (process != null) { EnvDTE80.Process2 p2 = (EnvDTE80.Process2)process; try { p2.Attach2(); } catch (COMException) { } } else { throw new InvalidOperationException("Unable to debug the process: Visual Studio debugger not found."); } } }
public static void DebugAttachToNode(int subjectProcessId, int port) { // Register COM message filter on this thread to enforce a call retry policy // should our COM calls into the DTE (in another apartment) be rejected. using (var mf = new ResilientMessageFilterScope()) { EnvDTE.DTE dte = GetAllDTEs().FirstOrDefault(x => ProcessExtensions.IsProcessAAncestorOfProcessB(x.Key, Process.GetCurrentProcess().Id)).Value; if (dte == null) { dte = GetAllDTEs().FirstOrDefault().Value; } IEnumerable<EnvDTE.Process> processes = dte.Debugger.LocalProcesses.OfType<EnvDTE.Process>(); EnvDTE.Process process = processes.SingleOrDefault(x => x.ProcessID == subjectProcessId); if (process != null) { EnvDTE80.Process2 p2 = (EnvDTE80.Process2)process; try { p2.Attach2(); } catch (COMException) { } } else { throw new InvalidOperationException("Unable to debug the process: Visual Studio debugger not found."); } } }