The options available for
deploying apps depend on your deployment scenario and application type.
There are three main application types and each one requires a
different deployment scenario. Table 1 summarizes these various scenarios.
TABLE 1: Application Deployment Summary
APP TYPE |
APP CODE DEPLOYED TO |
APP PACKAGE DEPLOYED TO |
SharePoint-hosted |
N/A |
App catalog or Marketplace |
Provider-hosted |
Azure or other |
App catalog or Marketplace |
Autohosted |
Azure |
App catalog or Marketplace |
SharePoint-hosted apps are a bit simpler than the
others given that there isn’t any Web deploy package to have deployed,
and because they generally consist of HTML pages and JavaScript only.
SharePoint-hosted apps don’t have any other dependencies on a runtime
environment for this reason.
Provider-hosted apps are a bit more complex and
consist of just an app package without any Web deploy package in it.
This is because the provider of the app is already required to be
hosting it either in Azure or some other Internet-accessible location.
The provider of the app manages running the code for the app and any
associated databases or dependent resources.
Autohosted app packages are the only ones that
contain Web deploy packages and/or database packages. This is because
Autohosted apps are the only app types where SharePoint needs to take
both the Web deploy package and database package and deploy them to
Azure when the app is installed. Azure is currently the only option for
autodeployment in the Autohosted scenario.
1. SharePoint-Hosted App Deployment
SharePoint-hosted apps are the simplest
of the three app types to package and deploy because of the lack of a
code package and associated deployment steps. All that is required is
to package the application using the Publish wizard in Visual Studio
and then deploy the app to either the Marketplace or an app catalog.
After the app is deployed, users can install the app on their site.
When this occurs, SharePoint takes the app package, creates a new app
Web for that instance of the application, and provisions the pages and
content from the app package into it. Any custom UI actions and App
Parts are also deployed to the host Web.
Try your hand at deploying a SharePoint-hosted app in the next exercise to learn how straightforward the process is.
Deploying a SharePoint-Hosted App
In this example you create a very
basic SharePoint-hosted app using Visual Studio 2012 development tools
and deploy that new app to the app catalog. You will need to use the
app catalog created from the previous Try It Out, “Creating a Private
App Catalog in Office 365.”
1. Ensure you have created an app catalog. See the earlier exercise, “Creating a Private App Catalog in Office 365.”
2. Open Visual
Studio and create a new app for a SharePoint 2013 project called
SharePoint Hosted App by selecting File ⇒ New Project ⇒ App for
SharePoint 2013. In the Name field enter MySharePointHostedApp.
3. In the New Project wizard specify SharePoint-hosted as shown in Figure 1.
4. After the
project has been created, right-click the project and select Publish.
The publishing wizard for the application launches; see Figure 2.
5. Click Finish. A new Windows Explorer window opens with your application package called MySharePointHostedApp.app showing.
6. Open a browser window and navigate to the tenant admin portal for your Office 365 environment at: http://portal.microsoftonline.com.
7. Under the Admin menu in the top navigation, click SharePoint to go to the SharePoint Online tenant admin pages.
8. Click apps in the left-side navigation.
9. Click the App Catalog link. The app catalog you created in the previous exercise appears.
10. Click the Distribute apps for SharePoint tile.
11. Click the New App button. A prompt appears asking you to pick the .app file for your application.
12. Click Browse and select the
.app
file that Visual Studio packaged for you in step 5. Click OK. A dialog
appears asking for information about your application, as shown in Figure 3.
13. You are
not required to enter any information unless you want to. Click Save to
proceed. You should now see your application in the app catalog, as
shown in Figure 4.
14. Navigate to your development site in SharePoint Online.
15. Click Site Contents in the left-side navigation.
16. Click Add an App.
17. Click From Your Organization in the left-side navigation and you should see your newly added application listed, as shown in Figure 5.
18. Click the
tile for the application and click Trust It when prompted. SharePoint
Online begins to provision your app in the site.
19. When the
process completes, click the newly installed app tile. The Start page
for your application appears; your username will be listed as shown in Figure 6.
How It Works
In this exercise you created
a rudimentary SharePoint-hosted app that simply lists the name of the
currently logged-in user. You packaged the app ready for deployment
using the Publish wizard in Visual Studio and then uploaded and
configured the app in the app catalog in SharePoint Online. You then
installed the app on a SharePoint Online site. Behind the scenes,
SharePoint created a new SharePoint site specifically for this
installation of the application and deployed the application’s assets,
such as pages and JavaScript, to the appropriate places. You can see in
the URL for the app the domain name created and set up specifically for
the app instance. These steps are done on demand each time a
SharePoint-hosted app is installed. When the application is run it uses
the JavaScript Client-Side Object Model to make a call to web.get_currentUser(); to retrieve the currently logged-in user. This code is in the /Scripts/App.js file in the Visual Studio project.