因此,我正在调试一些在单独的应用程序池中本地运行的网站(一个来自主干,一个来自分支)。我在两个 VS 实例中打开了主干和分支解决方案。我想在一个中调试主干,在另一个中调试分支。我想知道是否有一种方法可以知道每个 w3wp.exe 正在服务哪个应用程序池,以便在附加调试器时知道哪个是哪个应用程序池。
更新:这样做的目的是在 VS 中编写一个宏,然后让我有一个按钮(每个有趣的应用程序池),可以单击该按钮来附加调试器。因此解决方案最好不涉及其他程序。
Update2:这是在 Windows 7 上针对 IIS7 的。
下面是我的核心宏。编写一些单行子程序来调用它,例如AttachToW3wp("DefaultAppPool")
命名您感兴趣的每个应用程序池,并为它们制作按钮和热键。
Private Sub AttachToW3wp(ByVal appPoolName As String)
Const processName As String = "w3wp.exe"
Dim userName As String = String.Format("IIS APPPOOL\{0}", appPoolName)
Try
Dim debugger As EnvDTE90.Debugger3 = CType(DTE.Debugger, EnvDTE90.Debugger3)
'debugger.DetachAll()
Dim transport As EnvDTE80.Transport = debugger.Transports.Item("Default")
Dim qualifier As String = Environment.MachineName '= My.Computer.Name
Dim engines(3) As EnvDTE80.Engine
engines(0) = transport.Engines.Item("Managed")
engines(1) = transport.Engines.Item("Script")
engines(2) = transport.Engines.Item("T-SQL")
Dim successMessage As String = String.Empty
For Each process As EnvDTE80.Process2 In debugger.GetProcesses(transport, qualifier)
With process
Dim fi As New System.IO.FileInfo(.Name)
If fi.Name = processName AndAlso (String.Compare(.UserName, 0, userName, 0, Len(userName), True) = 0) Then
If .IsBeingDebugged Then Throw New Exception(String.Format("{0} {1} is already attached to a debugger.", processName, userName))
process.Attach2(engines)
successMessage = String.Format("Attached to {0} for {1} ({2})", processName, userName, .ProcessID)
Exit For
End If
End With
Next
If successMessage = String.Empty Then
Throw New Exception(String.Format("{0} {1} not found.", processName, userName))
Else
Trace.WriteLine(successMessage)
End If
Catch ex As System.Exception
MsgBox(ex.Message)
End Try
End Sub
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)