Thursday, March 17, 2011

Debugging SharePoint 2010 Web Parts from Visual Studio 2010


Most of you probably already have figured this out, but for those of you who still have not, here is how you can debug your web part in Visual Studio 2010:
  1. Deploy your Web Part
  2. Add the Web Part to Page
  3. In your code, create a break point.
  4. Go to “Debug” menu, and choose “Attach to Process”.
  5. Under “Attach to:” section, click on “Select …” button.
  6. Uncheck all options, checking ONLY “Managed (v2.0, v1.1, v1.0) code”.
  7. Check the “Show processes in all sessions” checkbox.
  8. Select all “w3wp.exe” Processes, then click on the “Attach” button.
  9. Run your page that contains the Web Part. You should now hit your break point, and will be able to step through your code.

This should help speed up your development considerably if you are not using this method already.

Thanks,
Pete Soheil

3 comments:

Raghav said...

Thank You.

--Raghav

Anonymous said...

My favorite technique: Don't debug SharePoint Web Parts! Build a Windows Console App and do your debugging there instead.

1) Create a windows console app
2) Copy all the relative code from the web part
3) Replace any ASP.NET control output with Console output
4) Debug and step through
5) Copy the fixed code back to the web part.

Cheers!

DigiOz Multimedia said...

That will certainly save you quite a bit of time. Thanks for the hint Jonathan.