Wednesday, December 23, 2009

Tips to deploying/debugging

Just like when debugging a normal .NET application you need to restart the app domain to load the new code and get the debugger to attach the code. In a normal SharePoint project you need to attach to the w3wp.exe process, the w3wp.exe is the application pool that runs the SharePoint instant, to load the new code, you need to restart the application pool by doing an iisreset or just recycle the application pool e.g. thought IIS manager. The sandbox solution is not run by the w3wp.exe, but a SharePointUserCode worker process (SPUCWorkerProcess.exe). This is managed by the Windows services "Windows SharePoint Services User Code Host V4" (SPUserCodeV4). So by restarting this service the sandbox solution code the now reloading next time the code is requested and ready to get debugged. So how to restart this services? One way is to start services.msc and restart the service that way or use net stop/net start or just use Power Shell.

So by run this Power Shell "restart-service -name spusercodev4" the Services User Code Host gets restarted, but you need to do this manually every time you redeployed your sandbox solution code. So to overcome this, just add a line to the "Pre-build events command line" in your Visual Studio project "powershell restart-service -name spusercodev4" and it will do the trick.

Buld events

2 comments: