October 4, 2012

The most useful shortcut for VS 2010

UPDATE: For visual studio 2012, you may install the great extension "AttachTo" via the "Extension and Update" of visaul studio. Here is maybe the most useful keyboard shortcut you can create in visual studio for the web development.
Don’t you have dream to push on one shortcut only to attach to the w3wp process without accept all the dialog boxes?
This is the equivalent of pushing on ctrl+alt+p (open attach to process window), w (go to the letter w), enter (to accept to attach).

Here is the method to do that with only one key combination:
  1. Click on “View” – “Other windows” – “Macro Explorer” (or alt+F8)
  2. Right click on “MyMacros” – “New Module”
  3. Name it “MyCustomMacros” for example and click on “Add”
  4. Replace the content of the file by:
    Imports System
    Imports EnvDTE
    Imports EnvDTE80
    Imports EnvDTE90
    Imports EnvDTE90a
    Imports EnvDTE100
    Imports System.Diagnostics
    
    Public Module MyCustomMacros
    
        ' This subroutine attaches to calc.exe if it is running.
        Sub AttachToW3WP()
            Dim attached As Boolean = False
            Dim proc As EnvDTE.Process
    
            For Each proc In DTE.Debugger.LocalProcesses
                If (Right(proc.Name, 8) = "w3wp.exe") Then
                    proc.Attach()
                    attached = True
                    'Exit For
                End If
            Next
    
            If attached = False Then
                MsgBox("Could not find w3wp")
            End If
    
        End Sub
    End Module
    
  5. Right click on the toolbar zone (on the left of “help” for example) and select the latest option: “Customize…”
  6. Click on the “Keyboard…” button
  7. In the “Show commands containing” search for “w3w” for example

  8. Select the new macro and in the “Press shortcut keys” box type a shortcut. Don’t forget to push on “Assign”

3 comments:

  1. How do you manage when you have >1 w3wp process? I typically have multiple websites running, each in their own app pool and process.

    Is there some logic/heuristic that could be used to be able to to tie a solution to a particular process?

    ReplyDelete
  2. You need to change the if to add your 'if' condition (you can test the property Username who contain the application pool user for example) and uncomment the Exit For to quit the for loop.

    ReplyDelete
  3. Makes sense, thanks, will look into this :)

    ReplyDelete