6

私は通常、Web アプリを開発していますが、驚くほど多くの作業時間を「Ctrl + Alt + P」、プロセス名で並べ替え、w3wp.exe を選択してデバッガーをアタッチすることに費やしています。

さらに悪いことに、私は複数のアプリケーション プールにまたがるアプリに取り組んでいるので、通常は w3wp.exe のインスタンスが 2 つまたは 3 つあり、どれにアタッチすればよいかを知ることは不可能であるため、通常はすべてにアタッチすることになります。それらのうち、これはやり過ぎですが機能します。

全体として、これはかなり面倒です...

私の同僚は、VS マクロを 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 のすべてのインスタンスにアタッチするように変更する方法はありますか?

4

4 に答える 4

8
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
于 2009-05-07T15:09:01.437 に答える
1

このタスク用のマクロを探していることは承知しており、同様のマクロを持っています。ただし、デバッグを開始するときに、ソリューション内のプロジェクトにデバッガーをアタッチする方法を説明したいと思います。

これはあまり知られていない機能です。ソリューション ブラウザーでソリューション ファイルを右クリックし、[プロパティの選択] を選択すると、複数のスタートアップ プロジェクトとそのアクションを定義できます。デバッガーを実行すると、リストされたプロジェクトにアタッチされます。

注: Web サービスがある場合、ブラウザ ウィンドウが開きますが、プロジェクトのプロパティでウィンドウを開かないように指定することで無効にすることができます。

于 2010-06-21T02:55:16.363 に答える
1

これは、リモートの w3wp プロセスにアタッチする方法です。これは、DanC のソリューションよりも少し速く実行され、エラー処理が追加されています。

Private Sub AttachToW3wp(ByVal machineName As String)
    ' In order for this to work, you have to be running the Visual Studio 2010 Remote Debugging Monitor
    ' as your (domain) user.  
    ' It won't work if the remote debugger is running as a service.  I've tried every permutation of 
    ' domain and username in the the transport qualifier, tried the obvious local system username,
    ' even tried looking at the network traffic 
    ' in WireShark, I can't figure it out how to make it work if you are running as a service.  
    ' If you are running the debugger as a service, even running the macro that gets created by VS's 
    ' macro recorder when you attach to a process doesn't work.
    Dim transportQualifier = machineName
    Try
        Dim processToAttachTo As String = "w3wp.exe"
        Dim dbg2 As EnvDTE80.Debugger2 = DTE.Debugger
        Dim trans As EnvDTE80.Transport = dbg2.Transports.Item("Default")
        Dim dbgeng(2) As EnvDTE80.Engine
        dbgeng(0) = trans.Engines.Item("T-SQL")
        dbgeng(1) = trans.Engines.Item("Managed (v2.0, v1.1, v1.0)")
        Dim processesRemote = dbg2.GetProcesses(trans, transportQualifier)
        Dim attached As Boolean = False
        Dim processRemote As EnvDTE80.Process2
        For Each processRemote In processesRemote
            ' For some reason it takes a much longer time to get the remote process names then it 
            ' does the user name, so let's skip over all the processes that have the wrong UserName.
            If processRemote.UserName = "NETWORK SERVICE" AndAlso _
               (Right(processRemote.Name, Len(processToAttachTo)) = processToAttachTo) Then
                If processRemote.IsBeingDebugged Then
                    MsgBox(processToAttachTo & " on " & machineName & " is already being debugged")
                Else
                    processRemote.Attach2(dbgeng)
                End If
                attached = True
            End If
        Next
        If Not attached Then
            MsgBox(processToAttachTo & " is not running on " & machineName & ".")
        End If
    Catch ex As System.Exception
        MsgBox("Exception attempting to attach to " & transportQualifier & ": " & ex.Message)
    End Try
End Sub
于 2012-04-04T17:56:42.340 に答える
0

gflags.exeを確認してください。そのオプションの 1 つは、特定の実行可能ファイルのすべての呼び出しに接続して実行するデバッガーです。

于 2009-05-05T01:54:18.947 に答える