 |
 |
|
SharePoint Quick Links
|
Article Categories
|
Archives
July, 2008 (13)
June, 2008 (12)
May, 2008 (23)
April, 2008 (12)
March, 2008 (15)
February, 2008 (13)
January, 2008 (12)
December, 2007 (10)
November, 2007 (8)
October, 2007 (15)
September, 2007 (20)
August, 2007 (21)
July, 2007 (16)
June, 2007 (8)
May, 2007 (25)
April, 2007 (16)
March, 2007 (18)
February, 2007 (18)
January, 2007 (12)
December, 2006 (16)
November, 2006 (13)
October, 2006 (18)
September, 2006 (22)
August, 2006 (27)
July, 2006 (23)
June, 2006 (23)
May, 2006 (23)
April, 2006 (9)
March, 2006 (17)
February, 2006 (15)
January, 2006 (23)
December, 2005 (31)
November, 2005 (32)
October, 2005 (38)
September, 2005 (53)
August, 2005 (30)
July, 2005 (63)
June, 2005 (30)
May, 2005 (59)
April, 2005 (29)
March, 2005 (74)
February, 2005 (27)
January, 2005 (22)
December, 2004 (32)
November, 2004 (42)
October, 2004 (39)
September, 2004 (20)
August, 2004 (14)
July, 2004 (27)
June, 2004 (40)
May, 2004 (5)
April, 2004 (6)
March, 2004 (16)
February, 2004 (26)
January, 2004 (23)
December, 2003 (7)
November, 2003 (14)
October, 2003 (20)
September, 2003 (4)
|
Post Categories
|




|
 |
|
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 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
 click to enlarge |
 click to enlarge |
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:
Setup 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 commeted it so you can understand what’s going on (or you can get it here):
' This routine attaches to the ASP.NET worker process Sub AttachTo_ASPNETWP() Dim attached As Boolean = False Dim proc As EnvDTE.Process Dim processToAttachTo As String
' name of the process to attach to processToAttachTo = "aspnet_wp.exe"
' iterate through all processes running on the local machine For Each 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 ' appach to the process proc.Attach() ' set a flag that we've attached to the process & exit the for loop attached = True Exit For End If Next
' if macro didn't find process running, notify user If attached = False Then MsgBox(processToAttachTo & " is not running") End If End Sub
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 develoeprs (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 resizeable? 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 CRTL+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 [A]ttaching to the process P:
 click to enlarge |
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 (CTRL+SHIFT+B), hit your key combination to attach to the process.
Happy debugging!
[Update 5/10/2006 2:20p EDT]: Technically you CAN debug Web Parts by simply hitting F5, but you have some extra config work to do in Visual Studio and SharePoint. Thanks to Maurice for pointing this out.
posted on Wednesday, May 10, 2006 9:19 AM
|
|
MOSS WCM Training
|
|
JAX Office Geeks
Jacksonville Office Geeks (JOG)
JOG is a special interest group in Jacksonville, FL dedicated to bringing the local SharePoint commnity together to share tips, tricks, ideas and best practices for developing solutions on the SharePoint platform.
Next meeting details...
When:
» TBD
Topic:
» TBD
Speaker:
» TBD
» Subscribe to the JOG newsletter
|
|
|
|