For SharePoint developers frustrated with attaching IIS processe to the debugger or are accustomed to debugging a webservice hosted in IIS, this article will help you speed up your development work or at least save a few minutes/seconds.
Do you know that any process 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 of other developers.
Use the following to understand how to attach a process to a debugger:
- Go to Tools -> Macros -> MacroExplorer
- Add a new Item in MyMacros (a new module file). Name it as you wish.
- Paste the following code in it. Make sure to change the module name to 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
- Build it (optional).
- Again go to Tools-> Customize
- Click on the Keyboard button at the bottom
- Now type macros.my and your macro will be shown in the filtered list; select it.
- Assign a short key to it and set apply.
Now forget about the headache of attaching to an IIS process every time. Just press your shortcut key. (Make sure you're running your Visual Studio with administrator privilege.)
Have fun. Cheers!!