Why Developer Site Definition For SharePoint Add-Ins

Sometimes a question arises in our minds! 

Why only developer site definitions for SharePoint Add-Ins?

There are cases when we want to enable the developer site collection feature when we need to side-load an app and deploy directly from Visual Studio. There isn’t a button in the site collection features, to let you enable this.

When we are creating a development environment and we want to deploy our apps to our SharePoint website from Visual Studio, we shall need to use a Developer site template or another template which has side loading of apps enabled.

Only use side loading of apps for development purposes. So, don’t use it on any production environment. To enable the side loading of apps for a specific SharePoint website, use the following PowerShell script.

On-Premises Environment

Add-PSSnapin Microsoft.SharePoint.PowerShell

Enable-SPFeature e374875e-06b6-11e0-b0fa-57f5dfd72085.

SharePoint Online

We cannot do the above approach with SharePoint Online as Windows PowerShell cmdlets don’t expose the ability to turn features on and off. Now, we have seen it for Client-Side Object Model. The other way is to use SharePoint Client Browser for SharePoint 2010 and 2013. It includes an extremely useful feature to open up the PowerShell with CSOM already loaded.

PowerShell window

We can, then, easily use the Client Side Object Model (CSOM) to enable the developer feature.
  1. $ctx.Load($ctx.Site);  
  2. $ctx.ExecuteQuery();  
  3. $guid = [System.Guid]"e374875e-06b6-11e0-b0fa-57f5dfd72085"  
  4. $ctx.Site.Features.Add($guid,$true,[Microsoft.SharePoint.Client.FeatureDefinitionScope]::None)  
  5. $ctx.ExecuteQuery();  
Using an Add-In

You have to perform following activities to accomplish this. 
  1. Replace app.js with the below code

  2. Go to the appmanifest for your app and request Manage permission for the site collection.

  3. Package SharePoint Add-In and then add the .app package to the app catalog for your tenant. Now, you can go to any site in your tenancy where you are a site collection administrator and add the app.

  4. Run the SharePoint Add-In.
    1. 'use strict';  
    2. var context = SP.ClientContext.get_current();  
    3. // This code runs when the DOM is ready and creates a context object which is needed to use the SharePoint object model  
    4. $(document).ready(function()  
    5.     {  
    6.     var site = context.get_site();  
    7.     context.load(site);  
    8.     context.executeQueryAsync(function() {  
    9.         site.get_features().add("e374875e-06b6-11e0-b0fa-57f5dfd72085"true, 0);  
    10.         context.executeQueryAsync(function() {  
    11.             alert("added the developer site feature to the site collection!");  
    12.         }, function(sender, args) {  
    13.             alert("unable to add the developer site feature to the site collection: " + args);  
    14.         });  
    15.     }, function(sender, args) {  
    16.         alert("oops! " + args);  
    17.     });  
    18. });