8-Week Microsoft Teams AppDev Accelerator Program
Limited seats available! - Start date: Wednesday, April 16, 2025
Join Today & Save $1,000
articles

When 'F5' debugging and attaching to processes is slow

Learn how you can speed up your debugging process in Visual Studio for SharePoint projects. Create a shortcut to launch & attach the debugger.

When 'F5' debugging and attaching to processes is slow
by Andrew Connell

Last updated May 10, 2006
4 minutes read

Share this

Focus Mode

  • The Problem
  • The Solution
  • Feedback & questions

Nothing new in this post… just seems ever few weeks/months you talk to someone that wasn’t aware you could do this. The last person I spoke to had a hard time finding this so I’m posting it for their, and now your, edification.

The Problem

MCMS 2002 and WSS v2 Web Part developers know that you can’t just hit F5 (see footer) to build and enter into your debugging environment without any extra configuration in Visual Studio. In order to debug your process, you do the following:

  • Build your solution
  • If it’s not already started, fire off one request to your solution/project/whatever to get the (in the case of IIS 5.x) ASP.NET worker process to start up or (in the case of IIS 6.0, w3wp.exe)
  • Using Attach the Visual Studio debugger to the process
  • Start debugging
Visual Studio Dialog

Visual Studio Dialog

Visual Studio Dialog

Visual Studio Dialog

That takes no fewer than 4 mouse clicks (VS Debug Menu > attach to process… > select aspnet_wp.exe/w3wp.exe > click OK). I’m not much of a mouse guy… much prefer shortcuts with my keyboard. The less I have to take my hands off the keyboard while working on a project, the more productive I can be. Not to mention, you could do this many times in the course of working on a project… say you jump into the debugger once every three minutes. On my relatively new laptop, that takes about 6 seconds. Over the course of a day, that adds up (for those few souls who actually work 8hrs a day, that’s just under 3 minutes a day). OK, so it’s not THAT much of an impact… but it’s a repetitive process… can’t that be automated? How do you get around this annoying use of the mouse?

The Solution

Set up a macro to automatically attach to the desired process, set a shortcut to trigger that macro, and another shortcut to detach from the process. The following assumes you’re working in Visual Studio 2005. The steps are similar if not identical in VS 2003. VS 2005 just has sexier screenshots (ok, just better looking). :P

First, we’ll create the macro:

  • Right-click MyMacros in the Macro Explorer tool window (bring up the Macro Explorer by pressing ALT + F8 ) and select New Module….
  • Give your module a name, I used VSDebugger.
  • Right-click your new module, in my case VSDebugger, and select New macro.
  • Change the name of the macro to something that makes more sense; I used AttachTo_ASPNETWP.
  • Replace the default macro added to your module with the following code. I’ve heavily commented it so you can understand what’s going on:
' This routine attaches to the ASP.NET worker
processSub AttachTo_ASPNETWP()
  Dim attached AsBoolean = False
  Dim proc As EnvDTE.Process
  Dim processToAttachTo AsString

  ' name of the process to attach to
  processToAttachTo = "aspnet_wp.exe"

  ' iterate through all processes running on the local machine
  ForEach proc In DTE.Debugger.LocalProcesses
    ' if the last [X] characters of the process name = name of the process...
    If (Right(proc.Name, Len(processToAttachTo)) = processToAttachTo) Then
      ' attach to the process
      proc.Attach()
      ' set a flag that we've attached to the process & exit the for loop
      attached = True
      ExitFor
    EndIf Next
  EndFor

  ' if macro didn't find process running, notify user
  If attached = False Then
    MsgBox(processToAttachTo & " is not running")
  EndIf
EndSub

Next, we need to create a keyboard shortcut:

  • In Visual Studio, open the Options dialog (Tools | Options).
  • Select the Keyboard node under the Environment category.
  • In the Show commands containing: textbox, enter VSDebugger (or the name you chose for your module) to find the command in the listbox.
    • To digress for a second… why in the world did the VS IDE developers (1) give us 10,000 items in such a small listbox (only see 5 items at a time) and/or (2) not make the Options dialog resizable? Man, that seems so obvious to fix.
  • Place the cursor in the Press Shortcut keys: input box and type the key combination you’d like to use to fire your macro off. As you can see in the screenshot, I use a two step command. I press CTRL + SHIFT + P , release, and then press A . Why? The first part is easy to remember as it’s binding to a process P . The second command is Attaching to the process:
Visual Studio Dialog

Visual Studio Dialog

Repeat the same process to create a shortcut to detach from the process. In this case, search for detachall… I used the key combination CRTL + SHIFT + P , D (so A attaches, D detaches).

Now you’re good to go! After building your solution ( CRTL + SHIFT + B ), hit your key combination to attach to the process.

Happy debugging!

Andrew Connell, Microsoft MVP, Full-Stack Developer & Chief Course Artisan - Voitanos LLC.
author
Andrew Connell

Microsoft MVP, Full-Stack Developer & Chief Course Artisan - Voitanos LLC.

Andrew Connell is a full stack developer who focuses on Microsoft Azure & Microsoft 365. He’s a 20+ year recipient of Microsoft’s MVP award and has helped thousands of developers through the various courses he’s authored & taught. Whether it’s an introduction to the entire ecosystem, or a deep dive into a specific software, his resources, tools, and support help web developers become experts in the Microsoft 365 ecosystem, so they can become irreplaceable in their organization.

Feedback & Questions

newsletter

Join 10,000+ developers for news & insights

No clickbait · 100% free · Unsubscribe anytime.

Subscribe to Andrew's newsletter for insights & stay on top of the latest news in the Microsoft 365 Space!
blurry dot in brand primary color
found this article helpful?

You'll love these!

What's next for Microsoft's Content Management Server?

What's next for Microsoft's Content Management Server?

January 10, 2005

Read now

Microsoft product build & version numbers for OSS developers

Microsoft product build & version numbers for OSS developers

November 27, 2005

Read now

Choosing a Primary Point of Entry for SharePoint and CMS

Choosing a Primary Point of Entry for SharePoint and CMS

October 27, 2004

Read now

bi-weekly newsletter

Join 10,000+ Microsoft 365 full-stack web developers for news, insights & resources. 100% free.

Subscribe to Andrew's newsletter for insights & stay on top of the latest news in the Microsoft 365 ecosystem!

No clickbait · 100% free · Unsubscribe anytime.

Subscribe to Andrew's newsletter for insights & stay on top of the latest news in the Microsoft 365 Space!