public
Last active

DebuggingMacros.vb

  • Download Gist
DebuggingMacros.vb
Visual Basic
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
' original code from Ingo Rammer (http://weblogs.thinktecture.com/ingo/2011/02/attach-to-process-macro-for-visual-studio-2010.html)
 
' ===== Create the Macro =====
 
' 1. Tools > Macros > Macro IDE
' 2. Right Click MyMacros > Add > Add Module
' 3. Paste in the code below:
' 4. Rename the Macro file DebuggingMacros
 
' ==== Add Macros to Debug Toolbar ====
 
' Enable the debug toolbar
' Click the dropdown on the far right and click "Add or Remove buttons" > click "Customize"
' Click "Add Command"
' Select Macro on the left panel
' Find the macro in the list on the right
' Click "ok"
' Click "Modify Selection" and rename the button
' * repeat for nunit macro
 
 
Public Module DebuggingMacros
 
Public Sub AttachToWebServer()
 
Dim AspNetWp As String = "aspnet_wp.exe"
Dim W3WP As String = "w3wp.exe"
 
If Not (AttachToProcess(W3WP)) Then
If Not AttachToProcess(AspNetWp) Then
System.Windows.Forms.MessageBox.Show("Can't find web server process")
End If
End If
End Sub
 
Public Sub AttachToNunitAgent()
 
Dim NunitAgent As String = "nunit-agent.exe"
 
If Not AttachToProcess(NunitAgent) Then
System.Windows.Forms.MessageBox.Show("Can't find nunit-agent process")
End If
End Sub
 
Public Function AttachToProcess(ByVal ProcessName As String) As Boolean
 
Dim Processes As EnvDTE.Processes = DTE.Debugger.LocalProcesses
Dim Process As EnvDTE.Process
Dim ProcessFound As Boolean = False
 
For Each Process In Processes
If (Process.Name.Substring(Process.Name.LastIndexOf("\") + 1) = ProcessName) Then
Process.Attach()
ProcessFound = True
End If
Next
 
AttachToProcess = ProcessFound
 
End Function
 
End Module

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.