I think SharePoint is a fantastic product, but developing with SharePoint can be a very frustrating experience.
Today, I was writing an Event Receiver so that when an item in a particular list was added or updated, it would send an email to the person who created the item and to the list administrator.
The first version of my event receiver assembly didn't generate any emails, so I needed to debug it in real time to find out where it was going wrong. This is what I had to do:
- Install Visual Studio 2005 on the SharePoint server.
- Copy the Visual Studio project from my PC onto the server.
- Build the project and install the assembly into the Global Assembly Cache (GAC).
- Register the event receiver with the list using a small console application.
- Perform an IIS reset, or recycle the application pool for the SharePoint web application.
- On the Visual Studio Debug menu, choose "Attach to Process..." and attach the debugger to all of the ASP.Net worker processes (w3wp.exe) running on the server.
- Set a breakpoint in the code.
- Open the SharePoint site in a browser, navigate to the list and add an item.
- Step into Visual Studio and step through the code line by line to identify the error(s).
- Stop debugging, edit the code and correct the error(s).
- Repeat from step 3.
After a while, this became really tiresome and repetitive and this got me wondering if there was a way to simplify the process.
It occurred to me that I could have used a Visual Studio post-build event to automatically install the assembly into the GAC and do an IIS reset for me. If you type "SharePoint post-build events" into your favourite search engine, you'll find lots of resources describing how to do this.
Unfortunately, by the time I realised this, my event receiver was almost finished and I decided it wasn't worth the extra effort for this particular project. But I'll certainly do this on my next project and I would urge all SharePoint developers to do the same!