Quick attach to process in Visual Studio

When i debug web applications i like to go with the attach to process instead of pressing F5 when i use IIS as the development web server. It has lot of advantages:

  • If you are “deep down” in your application you do not have to start from the beginning again. Attach to process lets you debug the tab/window you already using.
  • When you “press play” in VS and have Firefox as the default search engine you Visual Studio opens a new tab each time you start and you end up with X number of tabs with your app.
  • Probably more that i can’t think of right now.

Anyway the big disadvantage with this is that it is a pretty tedious process to attach to a process.

  • Press ctrl-alt-p to bring up the attach to process dialog.
  • Scroll down to w3wp.exe and “attach” it. For some reason it doesn’t work to press “w” here either so you have to scroll down manually.
  • Click ok and then you have to confirm that you really have to do it.

I have been doing this for months but today i decided to see if Google had any answer to my problem and surely it did. I found this question on Stackoverflow. The answer to the question was to record a macro in Visual Studio that do this for you.

  • Press ctrl-shift-r to start record the Macro.
  • Do the steps i described above to attach to the process.
  • Press ctrl-shift-r again to stop the recording.

Now you have the attach to process as a temporary macro and can run it with ctrl-shift-p. You will get an error if you try to run it when you already attach to a process and so on but it work. If you want to you can look for the error 0x8971001E and add DTE.Debugger.Stop(True) in the catch part of the macro.

You can also save the macro and add it to your toolbar, attach your own keyboard shortcut to it and so on. Check out this article about macros on “Switch on the code”.

2 Responses to “Quick attach to process in Visual Studio”

  1. Thanks for this tip! I was looking for this as well recently, found your post, and just implemented in VS08.

  2. This was great I’m sure will save me a ton of time. Thanks for posting!

Leave a Reply