Tuesday, June 28, 2011

How to Debug a Web Part for SharePoint 2010

The basic steps are as follows:

1) Open the solution with the web part(s)
2)Copy the assembly (after it has been built) to the bin directory of the WSS web site and be sure to include the.pdb files
3) Deploy the web part (copy to the bin with the pdb as above, import the part into the web part gallery so it is visbile, create a smaple page and add the web part to the page in design view and publish the page)
4) Place a break point on the code of interest in Visual Studio
5) Under the Debug Menu, select Attach to Process
6) Find the w3wp.exe process. If none exists, begin browsing to the site that has the web part you are debugging. (I usually conduct an IIS reset so that all of the w3wp.exe processes go away and the sole one that you are interested in is easier to find)
7) Watch as the page processes and as soon as your web part is hit, Visual Studio will load symbols and begin the debugging process

Hopefully now, rather than climbing thorugh stack traces, Response.Write output, etc. you can conduct full-fidelity debugging and shave days off of a task that would only take hours.

No comments: