By default in Visual Studio it takes several actions to attach to IIS (w3wp.exe). You have to open the attach to process window (Ctrl+Alt+P), select the option to show all processes, find w3wp.exe in the list and select attach; all of this is performed multiple times a day.
This post describes how to create a macro in visual studio then create a button for it and/or a shortcut key.
Creating the 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 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
Creating the button
Click on the commands tab, select the toolbar radio button and then select the menu you would like to add the button to. I have chosen to add my button to the debug menu. When you have done this click on the add command button.
My button
Creating the shortcut key
Summary
By following the steps detailed above you should now be able to attach to the web server with one key combination or one click. Saving you time by removing the need to manually select the process. The same rules as attaching to w3wp through the attach to process screen still exist, that is that w3wp.exe must be running first in order to attach to it.








No comments:
Post a Comment