我通常正在开发网络应用程序,我花费了大量的工作时间来做"Ctrl + Alt + P",按进程名称排序,并选择w3wp.exe来附加我的调试器.
更糟糕的是,我正在开发一个跨越多个应用程序池的应用程序,所以我通常有2或3个w3wp.exe实例,并且不可能知道要连接哪个,所以我通常最终会附加到所有他们,这是有点过分但有效.
总而言之,这非常烦人......
我的同事找到了一种让VS Macro自动附加到w3wp.exe的方法(他基本上记录了这个):
Sub AttachMacro() Try Dim dbg2 As EnvDTE80.Debugger2 = DTE.Debugger Dim trans As EnvDTE80.Transport = dbg2.Transports.Item("Default") Dim dbgeng(3) As EnvDTE80.Engine dbgeng(0) = trans.Engines.Item("T-SQL") dbgeng(1) = trans.Engines.Item("T-SQL") dbgeng(2) = trans.Engines.Item("Managed") Dim proc2 As EnvDTE80.Process2 = dbg2.GetProcesses(trans, "ENIAC").Item("w3wp.exe") proc2.Attach2(dbgeng) Catch ex As System.Exception MsgBox(ex.Message) End Try End Sub
我不确定是否所有这些都是必要的,或者其他什么,我从来没有为VS做过一个宏,我真的不知道从哪里开始.
是否有办法修改此宏,以便它不会将自身附加到w3wp.exe 的实例,而是将其自身附加到w3wp.exe的所有实例?
Sub MacroAttachToAllProcesses()
Try
Dim dbg2 As EnvDTE80.Debugger2 = DTE.Debugger
Dim trans As EnvDTE80.Transport = dbg2.Transports.Item("Default")
Dim dbgeng(3) As EnvDTE80.Engine
dbgeng(0) = trans.Engines.Item("T-SQL")
dbgeng(1) = trans.Engines.Item("T-SQL")
dbgeng(2) = trans.Engines.Item("Managed")
For Each theProcess As EnvDTE80.Process2 In dbg2.GetProcesses(trans, "COMPUTERNAME")
If theProcess.Name.Contains("w3wp.exe") Then
theProcess.Attach2(dbgeng)
End If
Next
Catch ex As System.Exception
MsgBox(ex.Message)
End Try
End Sub