在 VS2010 中,有没有办法知道给定的 w3wp.exe 正在服务哪个应用程序池,然后决定将调试器附加到?

发布于 2024-08-29 20:32:10 字数 282 浏览 2 评论 0原文

因此,我正在调试一些在单独的应用程序池中本地运行的网站(一个来自主干,一个来自分支)。我在两个 VS 实例中打开了主干和分支解决方案。我想在一个中调试主干,在另一个中调试分支。我想知道是否有一种方法可以知道每个 w3wp.exe 正在服务哪个应用程序池,以便在附加调试器时知道哪个是哪个应用程序池。

更新:这样做的目的是在 VS 中编写一个宏,然后让我有一个按钮(每个有趣的应用程序池),可以单击该按钮来附加调试器。因此解决方案最好不涉及其他程序。

Update2:这是在 Windows 7 上针对 IIS7 的。

So I'm debugging some websites (one from trunk, one from branch) running locally, in separate apppools. I have trunk and branch solutions open in two VS instances. I'd like to debug trunk in one, and branch in the other. I'd like to know if there's a way to know which application pool each w3wp.exe is serving, to know which one is which when attaching the debugger.

Update: the point of this is to write a macro within VS to then let me have a button (per app-pool that is interesting) which will be clickable to attach the debugger to. So solutions should preferably not involve other programs.

Update2: this is on Windows 7 against IIS7.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

耳钉梦 2024-09-05 20:32:10

下面是我的核心宏。编写一些单行子程序来调用它,例如 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

Below is my core macro. Write a few one-line subs calling it, like AttachToW3wp("DefaultAppPool") naming each app pool you’re interested in, and make buttons and hotkeys for them.

    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
烟凡古楼 2024-09-05 20:32:10

另一种选择是 WADA - W3WP Advanced Attacher视觉工作室画廊。我通过在扩展管理器的在线图库中搜索“附加工作人员”找到了它。

Another option would be the WADA - W3WP Advanced Attacher available in the Visual Studio Gallery. I found it by searching in the Online Gallery of Extension Manager for "attach worker".

命硬 2024-09-05 20:32:10

查看此问题的答案。您可以从命令窗口运行内置脚本来执行此操作。

Look at the answers to this question. There are built in scripts you can run from a command window to do this.

拍不死你 2024-09-05 20:32:10

If you can execute a request on each branch, you could use something like Process Explorer or Task Manager to see which ID is which possibly as one may be taking up CPU cycles that is currently processing a request assuming you can get such separation.

夏日落 2024-09-05 20:32:10

您可以使用任务管理器查看进程运行时的用户名(一般与应用程序池名称相同)和进程ID,但是您必须在任务管理器中打开这些列,同时还要打开进程名称必须与应用程序池相同(据我所知,这是默认值)。
另请注意,此页面上列出的所有方法可能只显示当前正在运行的进程,这意味着如果您的特定进程由于空闲时间而关闭,您必须首先使用该站点才能将该进程显示在列表中,在您的情况下,这意味着您应该首先访问所有站点以确保与它们关联的进程正在运行。

You can use task manager to view the user name under which the process is running (which in general is the same as the application pool name) and the process ID, but you have to turn on these columns in task manager, and also the process name has to be the same as the application pool (which is the default as far as I know).
Also note that all methods listed on this page might only display the processes that are currently running, which means that if your particular process has shut down due to idle time you have first to use the site in order to bring the process up in the list, and in your case it means you should first access all sites to make sure that the process associated with them is runing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文