Welcome to MSDN Blogs Sign in | Join | Help

Debugger "Feature" for SharePoint

While Windows SharePoint Services 3.0 provides an excellent platform for developing Web applications, debugging them can be a bit of a pain. It's often a case of finding the process ID (PID), attach the debugger, navigate to the error, rinse, and repeat, but programmers love to write code, not navigate through menus. J Fortunately, my good ol’ buddy from Microsoft Consulting Services and developer extraordinaire, Jonathan Dibble, created a nifty “Debugger Feature” that can be installed and activated on a SharePoint site to make the debugging experience much easier to initiate. Jonathan is a brilliant guy, but he’s too shy (for now) to engage the broad SharePoint community, so he has donated his code to Scot Hillier’s SharePoint Features project on CodePlex for all to share and hopefully extend. The blog entry below was jointly written by Jonathan and Scot.

<Lawrence />

Debugger Feature for SharePoint

When activated, the Debugger Feature adds an “Attach Debugger” menu item to the Site Actions menu (see picture below). The feature provisions a simple page, which executes the System.Diagnostics.Debugger.Launch statement, causing an exception to be thrown and the debugger to be auto-attached. In some cases, the debugger cannot attach – for example, when the AppPool is running under a different user account. When that happens, the page will at least give you the correct PID, so you can attach the debugger yourself.

debugger.gif

Figure: Attaching the Debugger from SharePoint

Beyond this very basic and useful function, this is a great example of how to write a simple SharePoint feature that provisions a page. Included in the VS 2005 solution project are all of the .XML and .DDF files needed to create a feature and then a solution cab file for deployment. Let's take a quick walkthrough of the most important files.

The first .XML file, feature.xml, is what defines the feature:

<?xml version="1.0" encoding="utf-8" ?>

<Feature Id="B5CF5C33-8178-4cb0-99DC-E14AA04D1C05"

   Title="Attach Debugger Feature"

   Description="Can be used in debug mode to attach a debugger to the site."

   Version="1.0.0.0"

   Scope="Web"

   xmlns="http://schemas.microsoft.com/sharepoint/">

   <ElementManifests>

      <ElementManifest Location="elements.xml" />

   </ElementManifests>

</Feature>

The complete set of parameters can be found at http://msdn2.microsoft.com/en-us/library/ms436075.aspx. The critical element for us is the ElementManifest element, which specifies where WSS can find the provisioning instructions for our feature. The path is relative to the feature.xml, which in turn is relative to C:\Program Files\Common Files\Microsoft Shared\web server extensions\12. More on this when we construct our solution’s .CAB file. For now, know that the feature.xml and elements.xml are usually in the same directory.

Elements.xml:

<?xml version="1.0" encoding="utf-8" ?>

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

   <!-- Add Command to Site Actions Dropdown -->

   <CustomAction Id="SiteActionsToolbar"

      GroupId="SiteActions"

      Location="Microsoft.SharePoint.StandardMenu"

      Sequence="2001"

      Title="Attach Debugger"

      Description="Attaches debugger to current site">

      <UrlAction Url="~site/_layouts/Debugger/AttachDebugger.aspx" />

   </CustomAction>

</Elements>

Right now, the documentation on the contents of the elements file is fairly light. Looking briefly at our CustomAction element, the important attributes are the GroupId and Location, which tell WSS where to place our new page (the site actions standard menu). The Sequence number is for sorting the menu, 2001 should ensure we are at the bottom. And most importantly is UrlAction, which tells WSS that this will be a hyperlink to the AttachDebugger.aspx page. Notice the relative path token ~site, which indicates the page is located in our current site.

From here, I'd suggest opening the VS 2005 solution file and taking a look around. Notice how the directory layout inside the solution is similar to the layout in C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE. This is also to facilitate feature development. Check out install.bat and see how we use xcopy to copy the dev tree to the template tree. (BTW, the commented lines in the install.bat should be obvious – we have no need to GAC our assembly or restart IIS for our feature, but you might in future features. It's there if you need them.)

Finally, lets look at how the .CAB file is created. The most important file is the .DDF file in the \WSP directory:

;

.OPTION EXPLICIT; Generate errors

.Set CabinetNameTemplate=DebuggerFeature.wsp

.set DiskDirectoryTemplate=CDROM ; All cabinets go in a single directory

.Set CompressionType=MSZIP;** All files are compressed in cabinet files

.Set UniqueFiles="ON"

.Set Cabinet=on

.Set DiskDirectory1=Package

manifest.xml manifest.xml

..\TEMPLATE\FEATURES\Debugger\feature.xml Debugger\feature.xml

..\TEMPLATE\FEATURES\Debugger\elements.xml Debugger\elements.xml

..\TEMPLATE\LAYOUTS\Debugger\AttachDebugger.aspx LAYOUTS\Debugger\AttachDebugger.aspx

It’s fairly easy to read, but take a look at the destination paths, which are relative to C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE. The location of the AttachDebugger.aspx file must match the TemplateFile Location path specified in the manifest.xml file:

<Solution SolutionId="3D615864-B200-4ff8-8D08-6D651CA9D5F6" xmlns="http://schemas.microsoft.com/sharepoint/">

   <FeatureManifests>

      <FeatureManifest Location="Debugger\feature.xml"/>

   </FeatureManifests>

   <TemplateFiles>

      <TemplateFile Location="LAYOUTS\Debugger\AttachDebugger.aspx"/>

   </TemplateFiles>

</Solution>

Once you've developed and deployed a feature or two, you'll have that light bulb (“a-ha!”) moment about how everything required to implement a feature relates to each other, and then you’ll want to create a SharePoint feature for every discreet piece of functionality that you’d like to add to SharePoint!

Published Tuesday, April 10, 2007 11:02 AM by sptblog

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Sharepoint Debugger

Tuesday, April 10, 2007 4:00 PM by Sharepoint Debugger

# SharePoint 2007 menu item to attach te debugger... cool!

The SharePoint team provided us with this blog post describing a feature to install in your SharePoint

Wednesday, April 11, 2007 3:27 AM by Serge van den Oever [Macaw]

# Feature to attach the debugger to MOSS

The Sharepoint team created a very nice example which automatically attaches the debugger to the active

Wednesday, April 11, 2007 6:04 AM by Portals & Integration blog

# Debugger Feature for SharePoint

A nice feature for most of the SharePointers: a debugger feature! On the Microsoft SharePoint Products

Friday, April 13, 2007 5:33 AM by Stef's SharePoint 2007 blog

# Sharepoint Weekly Roundup

STSADM.exe for Windows - Ronalus has done a Windows GUI for our fave command line tool Feature Events

Friday, April 13, 2007 8:11 AM by Arno Nel 2.0 - the Information Worker

# re: Debugger "Feature" for SharePoint

This is one of the best features yet. Thanks :)

Friday, April 13, 2007 9:46 AM by Wouter Stevens

# re: Debugger "Feature" for SharePoint

How can you put the permission on that option link

Monday, May 14, 2007 9:03 AM by Enoya2000

# SharePoint 2007: Tools Collection

Encontrei num post do blog do JOPX , este conjunto de tools para SharePoint 2007. SharePoint Tips Utility

Saturday, May 26, 2007 9:39 AM by Miguel Isidoro

# re: Debugger "Feature" for SharePoint

Great Tool! ...worked without a glitch for me (I have my webapp running under a service account, so it gives me the PID to attach to) and is also good sample code.

Thanks!

Monday, May 28, 2007 2:30 PM by Jennifer Neumann

# SharePoint 2007 Tools Collection v2

Another update: SharePoint Tips Utility Pack - package of SharePoint 2007 utilities for administrators

Wednesday, June 20, 2007 8:38 AM by Walter Stiers - Academic Relations Team (BeLux)

# Debugging Feature in SharePoint 2007

This posting is a little old, but relates directly to an older posting of mine on how to debug a SharePoint

Wednesday, July 04, 2007 10:31 AM by Technical Weblog of Eric Charran

# Debugging Feature in SharePoint 2007

This posting is a little old, but relates directly to an older posting of mine on how to debug a SharePoint

Wednesday, July 04, 2007 11:02 AM by Mirrored Feeds

# Debugging Feature in SharePoint 2007

This posting is a little old, but relates directly to an older posting of mine on how to debug a SharePoint

Wednesday, July 04, 2007 11:04 AM by Noticias externas

# re: Debugger "Feature" for SharePoint

Why is this easier than opening up a CMD prompt at %windir%\System32\ and running IISAPP.VBS?  I get the same PID information without installing anything extra.

Wednesday, July 18, 2007 10:48 AM by Fred Morrison

# More useful and (free!) SharePoint "Features" available at http://www.CodePlex.com/Features

About 6 months ago, I posted a guest blog entry by Scot Hillier, a SharePoint MVP, about the shared source

Tuesday, August 28, 2007 11:58 AM by Microsoft SharePoint Products and Technologies Team Blog

# More useful and (free!) SharePoint "Features" available at http://www.CodePlex.com/Features

About 6 months ago, I posted a guest blog entry by Scot Hillier, a SharePoint MVP, about the shared source

Tuesday, August 28, 2007 12:05 PM by Noticias externas

# 2007 MOSS Resource Links (Microsoft Office SharePoint Server)

2007 MOSS Resource Links (Microsoft Office SharePoint Server) Here is an assortment of various 2007 Microsoft

Wednesday, September 12, 2007 11:19 AM by The Boiler Room - Mark Kruger, Microsoft SharePoint MVP

# re: Debugger "Feature" for SharePoint

Where does the Debugger store the logs after you activate the debugger?

Wednesday, October 10, 2007 10:50 PM by Gary

# Useful Links on MOSS 2007

Following are some of the moss 2007 links which are really helpful to every one. http://wss.collutions

Tuesday, January 22, 2008 4:14 AM by KP Mani Sharepoint 2003 - MOSS 2007 Blog

# Useful Links on MOSS 2007

Following are some of the moss 2007 links which are really helpful to every one. http://wss.collutions

Tuesday, January 22, 2008 4:32 AM by SHAREPOINTBlogs.com Mirror

# SharePoint resources

Gracias a Mark Kruger (SharePoint MVP) por esta lista de recursos de SharePoint donde podréis encontrar

Monday, February 18, 2008 10:30 AM by SharePoint mola

# SharePoint resources

Gracias a Mark Kruger (SharePoint MVP) por esta lista de recursos de SharePoint donde podréis encontrar

Monday, February 18, 2008 11:17 AM by SHAREPOINTBlogs.com Mirror

# Debugging web parts and other SharePoint custom code

Here are some tips for debugging your SharePoint web parts and other custom code. 1. How do you debug

Wednesday, November 12, 2008 9:33 PM by Mark Arend

# SharePoint debugger feature

I would like to reference to an old post that appeared in 2007 on http://blogs.msdn.com/sharepoint ,

Wednesday, February 11, 2009 5:53 AM by BBB - Bas Blogging 'bout.Net

# WSS 3.0 & MOSS: Algunas herramientas de depuración (I)!

Si hace tiempo os hablaba de algunas de las herramientas (tengo m&aacute;s en el tintero) a tener en

Sunday, March 29, 2009 1:27 PM by Blog del CIIN

# SharePoint Development Debugging

I've been reading a lot of posts on how to get debugging going when attaching to the w3wp.exe process. Disable 'Enable Just My Code' in Visual Studio This blog post

Thursday, April 02, 2009 10:30 PM by Confluence: SharePoint Development Wiki

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker