Friday 15 January 2016

Publishing , Packaging & Deploying Provider Hosted App – Vol 2

This tutorial contains information about Packaging , Publishing & Deployment of Apps using Visual Studio 2012 or later.
Today we gonna discuss how to package our provider hosted application and publish it through App Catalog.The Publishing procedure contains two phase , in first we will publish the App Web Project and in second we’ll do it for all the App Projects.An App project is which is deployed/installed in SharePoint server(Online or On-Premise) pointing to a web application(Web App Project) hosted at some location(Infrastructure) provided by Organization i.e IIS Server or Windows Azure.


Some Prerequisites:
  • Microsoft SharePoint Server 2013 or SharePoint online(Office365).
  • Visual Studio 2012 with Office Developer Tools for VS2012 else VS2013(No need of additionally installing Developer Tools).

Setting the Scenario:

At this stage we are supposed to have Provider Hosted App working fine when deployed and Installed Directly using VS(Optional).This practically means we have ClientID, ClientSecret and IssurID in web.config of Web Project ,set and configured correctly to SharePoint.Refer this link to Know More.

Steps to Publish Provider Hosted App

It’s a Pre-Requirement from Microsoft that if our Provide hosted application has App Web Application i.e Web Project then we need to deploy it first after that we’ll publish our App Project.
Note:In order to deploy ClientID, ClientSecret and IssuerID to sharepoint along with Web Project we need to Publish(Register) it through SharePoint App Register Page.

Registering The App to SharePoint Server

you can open it for your site collection by appending “/_layouts/15/appregnew.aspx/” at last of URL.
For example: http://(server-name):(port-number)/_layouts/15/appregnew.aspx/

appregnew
On that page enter ClientId & ClientSecret in place of AppId and AppSecret Respectively.
Give tile of your app in Title text box and in App Domain enter the Server Name(Machine Name) already set as App domain in Central Admin where your App will be hosted.
Redirect URL is optional here. After all set up hit “Create”.
Next , we will move to Publish Our Web Project. Here are the steps:

Publishing App Web Project to SharePoint Server

    First of all in VS , select App Web Project say “DemoAppWeb”. Right click “DemoAppWeb” and click on “Publish”.It will open Publish Web Application Form.
  • Here the first step is to Choose/Import a Publish Profile or Create a new One.This Publish Profile basically specifies your Host Server for App Web.You can have more then one Profile based on your requirements.For now we are creating a new One.It will open create publishing wizard for profile.Enter the name for new Publish Profile.Hit next.
  • Now, For publish method we’ll choose Web Deployment Package.
  • Next give a path for package location where we gonna save this package file.you can store it anywhere say in “D:”drive.
  • After that give the site/application name where this Web Application going to be hosted in IIS Server.So give a path like this.
    http://(target-server-name):(port-number)/
    note:Save this “port-number” somewhere , as we need to create a site application in IIS Server with this same Port number which will act as Virtaul Directory for our App Web Project.
  • Then hit next tab.
  • Now comes the settings section , here we’ll choose “Release” as our option.Hit on next and Publish.This will create Some files along with a Zip File with name as“DemoAppWeb.zip”. Save location of this file.We’ll need it.

Hosting Web Project in IIS(local) Server

  • First of all unzip the “DemoAppWeb.zip” file it will create a folder with name “DemoAppWeb”. This Folder’s content will be used for the Virtual Directory we gonna create in Next Step.
  • Now browse to PackageTmp folder in the Extracted Zip Folder and copy its path.
  • Create a new App Pool in IIS Server using .Net Framework 4.0.
  • Now, we have to add a new Site in IIS Serer assign this App Pool created above to it and give it a port we have saved earlier for this purpose. I can remember we have giver 1234 as port number.:)
  • Click on Create website and it will create a new website under sites folder in IIS.
  • Open Authentications Settings for this website and Enable Windows Authentication and Disable Anonymous Authentication.
  • We have to give Read & Write Permission on this folder (PackageTmp) for “Everyone” and “IIS_IUSRS”Users.Find “IIS_IUSRS” by selecting the Server as location while adding the permission group.

Publishing App Project to be deployed via App Catalog

Now, the last step in Publishing is to publish and create package file for App Project. Follow below steps for this:
  • In VS Solution, right click on App Project i.e “DemoApp” in this example and select publish.
  • In Profile section, select an old profile or create a new one.We’ll go for new profile here.
  • Then it’ll ask for host location where this is gonna be hosted. Here give the URL of the App Web hosted on the IIS in “Hosting Web Project in IIS(local) Server” section above. i.e
    https://(target-server-name):1234/
    Note:For the https above we need to add https binding under Site Bindings with default port number for it.
    Or For you can put https:// for meanwhile just for publishing app. and later you can modify it back to https by editing .app file.This will work. HTTPS will not be supported by many browsers or ask for allowing content to render data,so better you make it HTTP only.
  • Provide ClientIDCertificatePath,CertificatePassword and IssuerID used in Web.config under App settings tag.
    webconfig
  • Now Click on Next and finish it Off.
  • After publishing successfully it will open the publish folder , there we can find “DemoApp.app” file very easily.This is our App file.

Deploying Provider Hosted App using App Catalog to SharePoint

Now, we need to just deploy this App to SharePoint Site Collection using App catalog.

Follow below Steps for Deployment.
  • In the App Catalog Site created in Target Web Application, add new app to the “Apps for SharePoint” list and browse to the .app file we got after publishing. Upload this .app file and fill the details form.
  • After this .app file is successfully added to the list of apps.Just select this app item and click on View Details page.
  • Add this App to the App Catalog.This will get added and listed in All Site Contents.
  • Next you need to Deploy it to the desired Site Collection under this Web Application.
  • At last consume this app from your target site collection and you are done.

No comments:

Post a Comment