Group Collaboration
Using TFS Online Hosted Build Controller to Deploy App to SharePoint 2013

In this post, I’ll explain how I packaged and deployed a SharePoint 2013 app to Office 365 SharePoint Online using Team Foundation Service in the cloud.  First of all, much of the credit should go to Alexander Vanwynsberghe for publishing this post about deploying SharePoint 2013 apps using your own TFS build server: http://www.alexandervanwynsberghe.be/deploying-sharepoint-2013-apps-with-tfs-2012/.  Where this differs is that we are using TFS completely in the cloud and preferred not to use our own build controller for this project so we are using the hosted build controller provided by TFS online.

Steps I Took

1. Download the “OfficeToolsAppTemplate” build process and PowerShell scripts from codeplex here: http://officesharepointci.codeplex.com/

Note: This template will help you to package your app to a .app file and the zip includes the scripts necessary to deploy the app to SharePoint.  See Alexander’s blog for specifics on these first 3 steps.

2. Include the deploy scripts and build process template from the zip file into your TFS project and add the build XAML file into your list of build process templates and select it for your build definition.

3. Update the parameters.ps1 file to use your credentials and URL to your SharePoint 2013 Office 365 site

4. This is key step:

  • The “SharePointAppDeploy.ps1” script has to import the SharePoint Online PowerShell Client module in order to connect to SP Online and deploy the app package to your site.
  • Cloud-hosted TFS has PowerShell, but does not include the SharePoint Online modules by default, so if you skip this step, you will get several errors when you try to run the build
  • To fix this, you need to add a folder into your DeployScripts directory called “Binaries” and drop your SharePoint Online PowerShell libraries into it.  If you have downloaded the SharePoint Online PowerShell Management tools, you should find them here:

C:Program FilesSharePoint Online Management ShellMicrosoft.Online.SharePoint.PowerShell

5. Grab the following two DLLs and put them in your “Binaries” folder:

  1. Microsoft.Online.SharePoint.Client.Tenant.dll
  2. Microsoft.Online.SharePoint.PowerShell.dll

6.  Open your Common.ps1 file from the DeploymentScripts folder and add the following two lines at the beginning of the function “Create-SharePointClientContext”:

Import-Module -Name “..BinariesMicrosoft.Online.SharePoint.Client.Tenant.dll” -DisableNameChecking

Import-Module -Name “..BinariesMicrosoft.Online.SharePoint.PowerShell.dll” -DisableNameChecking

These two lines will import the necessary PowerShell libraries into PowerShell allowing the script to connect to SharePoint 2013 for O365 and deploy your app as you need.  Save and check in all your files, kick off a build and you should be good to go.