Thursday 20 June 2013

Setting up SharePoint 2013 Apps

What a pain.

After spending almost a day configuring an environment to make SharePoint 2013 Apps work, I can only say that this is a painful process, but one that most developers will have to go through if they want to control an environment they wish to develop against.

I decided that I would plot my steps through this process to help someone else through the same journey, at least it's a map of URLs I visited and information I gathered while on my way through.  Hopefully, it will be useful...but if you have problems after reading and trying everything, don't ask me: I wouldn't consider myself an expert in configuring these things.  I get what I need done and working, then leave well alone so I can concentrate on using and developing against the product!

So here we go.

First of all I was starting with an OOTB SharePoint 2013 single-server installation - no tweaks, no customisations.  The server had Active Directory and Domain Name Server roles set up on it.  The server itself was running on my desktop as a HyperV with Window 2008 R2, and had 8GB of memory allocated to it (half the recommended settings of 16GB which, as you will see, did play a role in some of my problems).

Stage 1:  Getting started

Start: Set up the development environment for SharePoint 2013 - http://msdn.microsoft.com/en-us/library/ee554869.aspx
How to: Set up an on-premises development environment for apps for SharePoint - http://msdn.microsoft.com/en-us/library/fp179923.aspx
Configure an environment for apps for SharePoint (SharePoint 2013) -
http://technet.microsoft.com/en-us/library/fp161236.aspx
 
Stage 2:  Setting up Apps

At this point I thought that I was on the home straight - everything appeared to run fine with few issues.  Running the PowerShell did throw up an error in the last command in the example (Set-SPAppSiteSubscriptionName -Name "app" -Confirm:$false) which I investigated and found the following article:

Creating SharePoint 2013 Apps – Set the App Domain - http://yalla.itgroove.net/2012/09/creating-sharepoint-2013-apps-set-the-app-domain/

Stage 3:  Server Optimisation

The article seemed to indicate a memory issue so I then went down the road of optimizing my server, reducing the number of Service Applications that were necessary and applications running (I usually leave a PowerShell command window running, alongside Windows Explorer windows and IE, with Visual Studio, but I closed everything except my PowerShell window which I closed and re-opened to release any memory it may have been holding onto):

Optimizing Server Configuration for Development Farm - http://www.spdeveloper.co.in/sharepoint2013/optimizing-the-configuration-of-development-farm.aspx
 
Eventually, after shutting down all running applications and trying again, and still receiving the same error, I rebooted and tried again and I got the command to work.  It was time to create my first SharePoint 2013 App.

Stage 4:  My First SharePoint 2013 App (Part 1)

How to: Create a basic SharePoint-hosted app - http://msdn.microsoft.com/en-us/library/fp142379.aspx

So, I followed the example in the article (at this point I hadn't read the comments) but had several issues trying to deploy the project which led me to look at the following pages - the most obvious was the fact that the System Account cannot deploy an App (?):

Error Installing SharePoint 2013 App - http://social.msdn.microsoft.com/Forums/sharepoint/en-US/2bd11645-5ba2-40c5-8259-b0496b42d534/error-installing-sharepoint-2013-app
App deployment in SharePoint 2013 RTM - http://social.msdn.microsoft.com/Forums/sharepoint/en-US/9988a434-2787-4315-aeea-9f1707fb5a0b/app-deployment-in-sharepoint-2013-rtm
Error occurred in deployment step 'Install app for SharePoint': The provided App differs from another App with the same version and product ID - http://social.msdn.microsoft.com/Forums/sharepoint/en-US/152f3e26-fa84-49d9-a43c-6d339cddc435/error-occurred-in-deployment-step-install-app-for-sharepoint-the-provided-app-differs-from
 
Stage 5:  Memory

I had gone through everything but I was starting experience strange errors, which I considered unrelated to SharePoint specifically:

Compiler Error CS1012 - http://msdn.microsoft.com/en-us/library/185szk2f(v=vs.80).aspx
Too many characters in character literal? - http://stackoverflow.com/questions/7912819/too-many-characters-in-character-literal

Perhaps these too were memory errors, so I decided to run Visual Studio 2012 outside of my DEV HyperV server on my local machine instead, letting the server simply run SharePoint and nothing else.

Stage 6:  My First SharePoint 2013 App (Part 2)
 
I copied my files across from the server and opened them in Visual Studio 2012 locally, setting up my site path etc correctly and hit F5.  Errors again.  But this time it appeared that there were issues with the Content Database as I was seeing "The content database on the server is temporarily unavailable" in the output window, even though I could hit the site fine.

So that was my next trail to follow:

Install of Apps from visual studio 2012 + The content database on the server is temporarily unavailable - http://social.msdn.microsoft.com/Forums/sharepoint/en-US/77fd536f-35e1-478a-ade0-d56ced8de102/insall-of-apps-from-visual-studio-2012-the-content-database-on-the-server-is-temporarily
 
This led me to this SharePoint 2013 Configure Non-Farm User Account for App Development - http://community.zevenseas.com/Blogs/Akhilesh/Lists/Posts/Post.aspx?ID=10 which seemed to indicate that insufficient rights were granted to the account I was using.  Despite using an account that was a Site Administrator on my DEV site, the account itself needed certain privileges granted in the Database.  I tried this but it still did not work.
 
Stage 7:  My First SharePoint 2013 App (Part 3)
 
Frustration set in.
 
I then found this article from Microsoft which appears to accompany the March 2013 Cumulative Update: Enable apps in AAM or host-header environments for SharePoint 2013 - http://technet.microsoft.com/en-us/library/dn144963.aspx.  Some of the SQL User Mappings granted to the account I was using differ from the article from I found just before.  So I updated SQL again.
 
Still not working.  Taking a step back, I read an article about a similar problem which suggested the project had somehow become corrupted.  I looked back through what I had done and realised that it was certainly a possibility, after all, I had copied it from a separate server and assumed it would work.  So I deleted the project and retried it.

Stage 8:  My First SharePoint 2013 App (Part 4) - the Ecstasy

As you can guess from the title here, it was a moment of happiness that my App finally deployed.  It was short-lived, I have admit, as the example in the Microsoft article (How to: Create a basic SharePoint-hosted app - http://msdn.microsoft.com/en-us/library/fp142379.aspx) didn't work.  After I scrolled down through the comments of the article, some benevolent being had posted a working example of the JavaScript (App.js) which did sort things out fortunately.  Why Microsoft would put up something so blatantly wrong I don't know, but at least the correct version accompanies it, even if it is in the comments (my advice here is always check the comments: my experience of Microsoft code examples is at about a 50% success rate). 

Final Thoughts

Once things are done, it's done and you don't ever need to worry again...at least that's the theory.  In short, memory did play a part in my problems, so even an 8GB HyperV server isn't quite up to the job of serving up SharePoint 2013 without error, which, in fairness to Microsoft, is lower than their recommended 16GB. 

Hopefully, if you do encounter problems, some of the above will help.  I've seen plenty of people on the 'net struggling with this configuration and I guess any advice or help is useful.

2 comments:

  1. Further to compiling this blog article, I also found this great run-through: start to finish - https://www.nothingbutsharepoint.com/sites/devwiki/articles/pages/configure-an-environment-for-apps-for-sharepoint-2013.aspx

    ReplyDelete
  2. With the SharePoint platform, SharePoint consultants work hand in hand with their clients in order to customize the entire SharePoint environment.

    ReplyDelete