Visual Studio - Attach to process shortcut

Visual Studio

Visual Studio Problem Overview


When I want to debug I have to do Debug->Attach to Process -> Look for a process in the list -> Attach.

I was wondering if I can create some kind of a shortcut to do this for me?

Visual Studio Solutions


Solution 1 - Visual Studio

The shortcut is Ctrl+Alt+P in Visual Studio 2005 and above.

Solution 2 - Visual Studio

The easiest way to do this is to write a macro which finds the DTE.LocalProcess you wan to target and automatically attach. For example

Public Sub AttachShortcut()
  For Each proc In DTE.Debugger.LocalProcesses 
    If proc.Name = "what you're looking for" Then
      proc.Attach()
      Exit Sub
    End IF
  Next
End Sub

Note: This Stack Overflow Question is related and has a sample you may find useful

Solution 3 - Visual Studio

Writing a macro is one option, however it cannot deduct which process to attach to by itself.

Another nice solution is to map the "Attach to process" command to a shortcut key:

(Tools -> Options -> Environment -> Keyboard, type attach, like i did in this example, and select a shortcut key):

enter image description here

Solution 4 - Visual Studio

You can use the Alt key shortcut ALT+D,P to launch the "Attach to Process" window via Debug menu.

Once there, you can use your keyboard to search the list of Available Processes (e.g. type "w3wp" if you want to attach to an IIS app pool)

Solution 5 - Visual Studio

This answer should work for Visual Studio 2010.

> I like having buttons to do this on my debug toolbar

https://gist.github.com/1406827

The gist contains a method for attaching to IIS (w3wp.exe) or ASP (aspnet_wp.exe) and also nunit (nunit-agent.exe). Instructions are included on how to add the macros to your debug toolbar.

Solution 6 - Visual Studio

Attach to Process Button

To enable the 'Attach to Process' toolbar button in Visual Studio 2013, 2015, 2017, and 2019

  1. Right-click on any toolbar and click 'customize...'
  2. Click the 'commands' tab
  3. Click the 'Toolbar' radio button
  4. Select the toolbar where you want your button to appear from the dropdown
  5. Click the 'Add Command...' button
  6. Select 'Debug' from the categories list on the left
  7. Select 'Attach to Process' from the commands list on the right, and click ok. The button will appear on your selected toolbar.
  8. Optionally, use the 'Move Up' and 'Move Down' buttons on the right to move your new button to your desired location within the toolbar. I keep mine just after the Debug button.

Solution 7 - Visual Studio

For Visual Studio 2017, 2019, there is a ReAttach extension available. Very handy.

Solution 8 - Visual Studio

I use this built in "Shortcut"

ALT+D, P, W, ENTER

this opens the debug menu, selects attach to process, scrolls down to w3wp.exe and attaches.

It's long but should work in multiple visual studio versions with no setup required, with or without resharper and it works when running multiple IIS processes as you can choose which process to attach to.

Solution 9 - Visual Studio

Addins are probably a better way to do this now. I use one called "Attach to anything". You can find them in Visual Studio 2012. Go to "Tools" -> "Extensions and updates", search for "attach", and install "attach to anything".

Also see: https://stackoverflow.com/questions/15130239/automate-attach-to-process-in-visual-studio-2012

Solution 10 - Visual Studio

Alt+Shift+P to reattach the last attached process.

It works for me in Visual Studio 2017.

Solution 11 - Visual Studio

Personally I prefer to use Debugger.Launch() as suggested here in this thread, because it doesn't need for references to the DTE (that's IDE-specific and must be explicitly referenced into the project to be used)

Solution 12 - Visual Studio

VS extensions

More: Search the VS Marketplace for "attach"

Keyboard

  • The attach to process shortcut is Ctrl+Alt+P in Visual Studio 2005 and above. You can then press the first letter of the process name you want, e.g. w for w3wp.exe and it'll jump to that, then Enter to attach.
  • You can use the Alt key shortcut ALT+D,P to launch the "Attach to Process" window via Debug menu.

Code


Current release is VS2015 at time of writing.

Go ahead and edit/extend this answer :-)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questiondev.e.loperView Question on Stackoverflow
Solution 1 - Visual StudioRajeshView Answer on Stackoverflow
Solution 2 - Visual StudioJaredParView Answer on Stackoverflow
Solution 3 - Visual Studiolysergic-acidView Answer on Stackoverflow
Solution 4 - Visual StudioTMcManemyView Answer on Stackoverflow
Solution 5 - Visual StudioBrian WiggintonView Answer on Stackoverflow
Solution 6 - Visual StudioTom BowersView Answer on Stackoverflow
Solution 7 - Visual StudioDawid SibińskiView Answer on Stackoverflow
Solution 8 - Visual Studioroo2View Answer on Stackoverflow
Solution 9 - Visual StudioJon ReaView Answer on Stackoverflow
Solution 10 - Visual Studiouser3463072View Answer on Stackoverflow
Solution 11 - Visual StudioNinjaCrossView Answer on Stackoverflow
Solution 12 - Visual StudioTim AbellView Answer on Stackoverflow