Saturday, February 5, 2011

Build SharePoint 2010 projects without SharePoint 2010 installed

Many developers have resorted to creating a virtual machine that has SharePoint 2010 and Visual Studio 2010 installed in order to develop Sharepoint projects. Or have both installed directly on a Windows 7 machine. I personally don't like either because the former setup is outrageously slow on almost any laptops, and the latter has an entire SharePoint hogging the Windows 7 machine all the time. I would rather work in the Visual Studio 2010 on my Windows 7 laptop, and deploy to a remote dev box or VM, which runs SharePoint only. Here's how to set up a Windows 7 machine with Visual Studio 2010 to fully develop and build SharePoint 2010 projects:
  • Create the folder C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14 on your Windows 7 machine
  • Copy the \14\ISAPI folder from a machine with SharePoint 2010 installed to the above folder. This way the assemblies are in the same location as they are on the SharePoint server.
  • Download Microsoft Chart Controls for Microsoft .NET Framework 3.5 and install it on the Windows 7 machine. Several SP 2010 assemblies (Microsoft.Office.Server, Microsoft.SharePoint.Taxonomy, etc) depends on System.Web.DataVisualization v3.5 in this package. The package installs to C:\Program Files (x86)\Microsoft Chart Controls and also puts assemblies in GAC.
  • Add the above assemblies to be recognized by Visual Studio 2010 by default (that is, show up in the Add Assemblies Dialog when clicking Add References. This is not absolutely necessary but makes life a whole lot easier. The registry entries also allow projects created on machines with SharePoint installed to be compiled without having to change anything, as some of the referenced assemblies are in the GAC on the SharePoint machine, and hence no path is specified in the project file.
    • Add the registry key:[HKEY_CURRENT_USER\Software\Microsoft\.NETFramework\v3.5\AssemblyFoldersEx\SharePoint] and give the default string the value of the path to the ISAPLI folder: C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI
      Visual Studio will display the assemblies in the Add Reference dialog for all SharePoint 2010 projects (which target .NET 3.5). Note that this must be added under the CURRENT_USER registry. The assemblies do not show up when this is added to the LOCAL_MACHINE registry, though Microsoft says either works.

For developing Silverlight 4 components for SharePoint 2010, do the following additional setups
  • Copy the \14\TEMPLATE\LAYOUTS\ClientBin folder from the SharePoint 2010 machine to the 14 folder created above. If you develop Silverlight 4 components for SP 2010, you need the two assemblies in this folder.
  • Add the above assemblies to be recognized by Visual Studio 2010 by default (that is, show up in the Add Assemblies Dialog when clicking Add References. Add the registry key:
    [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Silverlight\v4.0\AssemblyFoldersEx\SharePoint] with the deafult string value of C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\ClientBin
    Visual Studio will display the two assemblies in this folder in the Add Reference Dialog for any Silverlight 4 projects. Note adding this key to the LOCAL_MACHINE registry is fine.
  • Download and install Silverlight 4 Tools for Visual Studio 2010 if it's not installed.
  • Download and install Silverlight 4 Toolkit if it's not installed. It's not essential but most likely you'll need the toolkit.
Then you can develop SharePoint projects comfortably in your Windows 7 machine, deploy to and remote debug on another machine that runs SharePoint.