In VS2010, is there a way to know which application pool a given w3wp.exe is serving, to then decide to attach the debugger to?

后端 未结 5 1974
情深已故
情深已故 2021-01-07 14:03

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 l

相关标签:
5条回答
  • 2021-01-07 14:05

    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".

    0 讨论(0)
  • 2021-01-07 14:06

    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.

    0 讨论(0)
  • 2021-01-07 14:23

    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.

    0 讨论(0)
  • 2021-01-07 14:24

    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
    
    0 讨论(0)
  • 2021-01-07 14:28

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

    0 讨论(0)
提交回复
热议问题