TopMenu

Auto attach debugger to any process in visual studio

Specially, Sharepoint developers who are frustrated with attaching IIS process to debugger or who used to debug a webservice hosted in IIS. This blog post will help you speeding up your development work at least save few minutes/seconds.

Do you know, Any process that you need to repeat again and again can be automated in Visual Studio? How, Have you heard of Macros? Yes this is the key for winning this game and get a step ahead from co-developers.

 fast like ussain bolt(Image courtesy: www.elitefeet.com)

Follow the steps to get the process of attaching a process to debugger.

1. Goto Tools-> Macros->MacroExplorer

2. Add a new Item in MyMacros (a new module file). Name it as per your wish

3. Paste the below code in it. Make sure change the module name as per your new macro file name.

Option Strict Off
Option Explicit Off
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics

Public Module IISDebugAttach

Sub AttachDebuggerToIIS()
Dim processToAttachTo As String = "w3wp.exe"

If Not AttachToProcess(processToAttachTo) Then
MsgBox(processToAttachTo & " is not running")
End If
End Sub

Function AttachToProcess(ByVal processName As String) As Boolean

Dim proc As EnvDTE.Process
Dim attached As Boolean
For Each proc In DTE.Debugger.LocalProcesses
If (Right(proc.Name, Len(processName)) = processName) Then
proc.Attach()
attached = True
End If
Next

Return attached
End Function
End Module



4. Build it (optional).

5. Go to again Tools-> Customize

6. Click on Keyboard button at the bottom

7. Now type macros.my and your macro will be shown in the filtered list select it.

8. Assign a short key to it and set apply.

Now forget about the headache of attaching IIS process every time. Just press your shortcut key. (Make sure you’re running your visual studio with administrator privilege.)

Have fun. Cheers!!

No comments:

Post a Comment