Visual Studio - Attach to process shortcut
Asked Answered
S

12

71

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?

Sikes answered 14/7, 2011 at 16:31 Comment(1)
If you've situation like me, when you need to repeat the attach-to-processes operation using the same set of processes, grab resurrect extension and give it a try. It helped me so I've published it.Coastward
A
23

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

Andersen answered 14/7, 2011 at 16:36 Comment(5)
Macros are no longer available in Visual Studio 2012. For more details, see infoq.com/news/2011/10/VS-MacrosCletacleti
You can reuse macros code in VS 2012/2013 with Visual Commander vlasovstudio.com/visual-commanderSkyros
John Rea's answer below should be marked as the new answer, or at least have its information included in the answer for people using Visual Studio 2012 and up. The add-ins ReAttach and AttachTo are good examples.Levasseur
I've written a blog post about how to create a shortcut with the Visual Commander extension: blog.markvincze.com/attach-to-process-shortcut-in-visual-studioKirit
This should be downvoted now. Ctrl + Alt + P is the shortcut, as said in the answer from Rajesh.Australasia
E
86

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

Ecosphere answered 23/7, 2012 at 10:15 Comment(3)
would note that this get's hijacked by default re-sharper settings!Rolanda
@EruPenkman Not with the Visual Studio scheme (as of ReSharper 9 and Visual Studio 2013)Soldo
I've been using ALT+D, P. This is faster.Viviparous
A
23

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

Andersen answered 14/7, 2011 at 16:36 Comment(5)
Macros are no longer available in Visual Studio 2012. For more details, see infoq.com/news/2011/10/VS-MacrosCletacleti
You can reuse macros code in VS 2012/2013 with Visual Commander vlasovstudio.com/visual-commanderSkyros
John Rea's answer below should be marked as the new answer, or at least have its information included in the answer for people using Visual Studio 2012 and up. The add-ins ReAttach and AttachTo are good examples.Levasseur
I've written a blog post about how to create a shortcut with the Visual Commander extension: blog.markvincze.com/attach-to-process-shortcut-in-visual-studioKirit
This should be downvoted now. Ctrl + Alt + P is the shortcut, as said in the answer from Rajesh.Australasia
C
16

Attach to Process Button

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

  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.
Campo answered 27/7, 2015 at 9:52 Comment(0)
B
14

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

Bicentenary answered 14/7, 2011 at 21:10 Comment(3)
yes. this will open up attach to process window. the above macro goes further. it finds the process and attaches.Sikes
i was not sure which process it is that he's after. starting to like macros more and more recently :)Bicentenary
It should already have built in shortcut Ctrl+Alt+P. Might be different if you chose different kbd settings.Dumbfound
D
14

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)

Drumlin answered 24/8, 2014 at 16:7 Comment(0)
K
13

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.

Kitty answered 29/11, 2011 at 22:31 Comment(6)
I can't believe this answer hasn't got more votes yet. The steps are super easy to follow and it works perfectly. Thanks!Kilovoltampere
Adrian, glad it worked for you! This saved me a ton of time when I was doing .net work.Kitty
There are no macros in VS2012 so your answer is pretty uselessClamorous
DotNetWise: thanks, I've updated this answer to reflect that.Kitty
The link on github does not explain how to actually do the installation of the product. It's not user friendly. I'm not sure what to do with that code.Vienna
@Vienna There's instructions on how to install the macro at the top of the file. I haven't used VS in years though, so maybe I'm missing a critical step? Best of luck with this.Kitty
H
13

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

Hairpin answered 18/6, 2016 at 14:6 Comment(5)
This is the answer that worked for me. I'm unsure what the answers that suggest keyboard shortcuts are doing as that's not what the question was asking. Cheers!Microcircuit
VS 2019 is also supported.Candidacandidacy
I don't see VS2019 support listed in the marketplace.visualstudio.com/items?itemName=ErlandR.ReAttach you sure?Portingale
@MohammedDawoodAnsari I can see "Works with Visual Studio 2017, 2019". However, I don't use it anymore in VS 2019. In VS 2019 there's a built-in option for that: Debug -> Reattach to Process. It becomes available after you already attached to any process within given VS session.Tansey
Yes, you are right. VS 2019 got built in reattach, thanks.Portingale
R
12

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.

Rolanda answered 19/11, 2014 at 0:31 Comment(2)
If you (are able to) set up all websites to reuse the same apppool there will only be one w3p processJew
How do you build a shortcut?Precautionary
C
7

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: Automate "Attach to Process" in Visual Studio 2012

Carboxylase answered 11/11, 2014 at 9:53 Comment(1)
This should be marked as the new answer, since macros were removed in 2012. The add-ins ReAttach and AttachTo are good examples.Levasseur
P
4

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

It works for me in Visual Studio 2017.

Polanco answered 20/4, 2018 at 12:10 Comment(0)
P
0

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)

Postprandial answered 3/7, 2013 at 8:53 Comment(0)
H
0

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 :-)

Haplography answered 15/2, 2017 at 17:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.