Wednesday, December 7, 2011

SharePoint 2010 Code Review

Having a consistant approach to code reviews in any SharePoint development team can go along way to ensuring the solutions produced are of a high quality (or atleast a higher quality than would have been possible without the review). Not only do we get the benefits in terms of more robust, elegant solutions, it is also a very good knowledge sharing exercise for the reviewer.

Here are a few quick thoughts on what makes a good SharePoint code review (ignoring the standard C# questions, like comments, coding standards, error handing):
  • Have SharePoint objects such as SPSite and SPWeb been Disposed of appropriately?
  • Has the Developer run SPDisposeCheck on the solution and what were the findings?
  • Have Get methods been used where appropriate instead of using the index from a collection? ie oList.Items["abc"], as opposed to oList.GetItems(oQuery).
  • Does the developer make good use of CAML queries to avoid long running enumerations of SharePoint collections?
  • Has the developer overwritten throttling and if so, why?
  • When Running as Elevated Privledges has the AllowUnsafeUpdate been set back to False?
  • Is everything packaged in one or more features where possible?
  • Has the developer modified any Out of the Box SharePoint files? If so, calmly walk him off the premises.
  • When developing web parts, has the developer used RenderContents as opposed to CreateChildControls? If so, why?
  • ...what else?

Monday, July 11, 2011

Creating a SharePoint Virtual Machine Template

I thought I would take the time to detail my experiences with creating a SharePoint Virtual Machine template. This post elaborates on what is explained in the VMWare white paper here. Reading this whitepaper was a bit of a eurika moment for me, but in hindsight a fairly simple concept. Essentially this all boils down to two things:
  1. After installing SharePoint, ensure the check box Run the SharePoint Products and Technologies Configuration Wizard now is un-checked
  2. When creating an instance of the VM, run SysPrep

By doing these two things, you are ensuring you're not writing machine specific information to the database and secondly the machine is generating new system IDs.

Once the base was completed, I found we could intantiate clones of this base in a few hours (max). That includes copying the VM (say 100 gig), running sysprep, and running psconfig. Pretty sweet.

Building the VM template.

My Development VM consisted of the following (all installed as local administrator):
  • Windows Server 2008 R2 (64bit) 
  • SQL Server 2008 R2 
  • SharePoint Server (Enterprise) 2010 (and language packs where necessary) 
  • Visual Studio Ultimate 2010 
  • Office Professional Plus 2010 (x86) 
  • Visio Professional 2010 
  • SharePoint Designer 2010 
  • SharePoint WorkSpace 2010 
  • ULS Viewer 
  • SharePoint Manager 2010 
  • CKS Codeplex Visual Studio tools (v1.2)
  • PowerGUI 
  • ...obviously everything is service packed (except SharePoint). 
Once all the applications are installed, do an ipconfig /release and power off the VM.
Save a backup copy of the 'base'. Always a good idea.

Creating an instance from the Base VM

  1. Make a copy the SharePoint VM template from the base. 
  2. Rename the .vmx file and VM folder to the server name you will use. 
  3. Whilst the VM is off, edit it's properties and rename the Virtual Machine Name to the intended VM name before boot up. 
  4. When prompted, click "I copied it". 
  5. Log in as the Administrator.
  6. To run SysPrep, click to Start > Run, type sysprep and press OK. 
  7. Select Enter System Out-of-Box Experience (OOBE). Uncheck Generalize. As 'Shutdown Options' select Reboot
  8. After rebooting you’ll have to enter some data, for example, Country or region, Time and currency and Keyboard input. Also, accept EULA and reboot. 
  9. Change the local administrators password when prompted. 
  10. Right Click computer and click properties. Change the name of the server to the name that was changed in step 2. Remain in workgroups here. Do not join the domain yet. The system will ask you to reboot. 
  11. After the reboot, log back in as Administrator. 
  12. You’ll now attempt to join the domain. It might be a good idea to 'ping' the domain controller to see if the connection works. If it doesn’t you’ll probably have to change the VM’s network adapter from Bridged to NAT (that way you are using the host’s access to the domain). You will need domain admin access here to join the domain. 
  13. Optional: once the computer has joined the domain, don’t power it back on until you have moved the object to the appropriate OU. Some OUs in organisation get a lot more settings pumped down to them via the GPO. We have a developement OU where only the minimal stuff gets downloaded.
  14. Re-start the VM. 
  15. Log back in as local Administrator 
  16. Add your domain accounts as local administrators on the VM. 
  17. Also, you will need to give this account access to SQL as well. I tend to use the same domain account as the farm account and service accounts for SharePoint (obviously not advised for production but this is for dev only) 
  18. Log out and log in as this domain account. 

At this point you can now run the SharePoint 2010 Product Configuration Wizard (psconfig). An alternative approach here is to use the CodePlex project AutoSPInstaller (highly recommended). This will streamline your VM creation even better becuase it will create all the necessary service applications, and web applications, site collections, and farm solutions you like.

One thing to note: Every Microsoft product installed in the VM will have to be re-activated from a licensing perspective. This includes the OS. Don't bother activating the products in the base (and it pays to use your enterprise licenses not your MSDN license that everyone you share this base with will use. I learnt the hard way on that one)

Hope this helps a SharePoint development team build quicker VMs.