SPOnline: deploying web templates

This is the first blog in a new series of blogs about SharePoint Online development. For those of you who don’t know yet: SharePoint Online comes with Office 365 and basically is a special version of SharePoint which is being hosted by Microsoft. There are some do’s and dont’s when developing solutions for SharePoint Online which I will discuss here. The main one is: DO development sandbox solutions and DON’T expect your current knowledge to be appliccable  for SharePoint Online. Sure, it’s still SharePoint, but you need to consider some things.

Ok, first up: web templates. In an on-premise environment, you might consider building a web definition. Well that idea kind of dies with the notion that it’s not supported in a sandbox, since a site definition writes things to disc. Basic SharePoint Online rule: all things which write files to disc are prohibited.

Ok so what then? Well there is the option of using a web template (which is on it’s turn based on a web definition) and linking custom features to it which are deployed upon provisioning. But what’s a good place to start? You’ll notice that an empty web template will give you a broken site on which even deleting a web isn’t possible, so be carefull with that.

What I found is that the best way to start is to create an empty site in your SharePoint online environment. After you got one, save it as a template (site options => save site as template). This will get you a WSP file in your sandbox solution store, so SharePoint will actually generate your first sandboxed solution. Cool!

The next step is to download that file and save it to your local development machine. Then create a new project in Visual Studio and choose the ‘Import WSP Package’ project type for your new project. Select the freshly downloaded WSP file and Visual Studio will refactor a project based on the solution. When you package this solution and deploy it to SharePoint Online; you’ll end up with your Empty Site template again.

Now you can start and use this base project to add your own features and customizations. But deploying to SharePoint Online each time is annoying and costly timewise, so you’ll probably prefer a local deployment. You’ll also notice that your template breaks as soon as you try to deploy a new site based on that template. It will throw an exception that feature 232b3f94-9d6e-4ed6-8d55-04d5a44ac449 doesn’t exist and thus your site couldn’t be created. SharePoint is right about that: you don’t have that feature in your onpremise SharePoint installation. Easiest workaround: open up the onet.xml file created in your project (Web templates folder) and comment out this line:

<FeatureID={232b3f94-9d6e-4ed6-8d55-04d5a44ac449}Name=FeatureDefinition/232b3f94-9d6e-4ed6-8d55-04d5a44ac449 />

Now you should be able to deploy locally and start adding your own stuff to it. The local sandbox should work the same as the online one, so when your solution works locally, it should also work in the cloud. The advantage of developing stuff on your own box is that you can view log files, attach debuggers, etc. All things you’ll won’t be able to do in Microsofts own farm.

Related posts

Latest posts

Leave a Comment

Leave a Reply

Your email address will not be published. Required fields are marked *