Attach Debugger to multiple processes via powershell

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-06 06:05:12

To get hold of the active visual studio instance ...

$dte = [System.Runtime.InteropServices.Marshal]::GetActiveObject("VisualStudio.DTE")

... and to make it attach to a set of processes ...

($dte.debugger.localprocesses | Where Name -Match "proc(one|two).exe").Attach()

... it seems that a delay might be necessary between each attach if it takes too long otherwise visual studio is busy and rejects the call.

Thanks, softwarebear. I was not able to get your exact command line working, but after adding curly brackets and running at an Administrator Powershell prompt, this command line successfully attached the debugger to all the running w3wp.exe processes:

$dte = [System.Runtime.InteropServices.Marshal]::GetActiveObject('VisualStudio.DTE')
$dte.Debugger.LocalProcesses | Where {$_.Name -like '*w3wp.exe'} | %{$_.Attach()}

Ideally this could be executed from within Visual Studio with a keystroke, but Visual Studio doesn't support Powershell without an add-in, and the Macro editor was removed after VS2010. Following this advice I tried adding this ScriptBlock as an 'External Tool' in a powershell.exe command line, but it didn't attach the debugger and produced no output.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!