Posted by on Sep 27, 2015 in #Office365Dev, Visual Studio | 1 comment

One of the greatest things about building Office Add-ins is the fact that they will run in Office Online (for instance Word Online, Excel Online and PowerPoint Online). Bringing your Office Add-ins across a large set of operating systems and devices.

Obviously we will need to test and make sure that our Office Add-in works in these different environments. As of right now, you can easily launch your Office (task-pane/content) Add-ins in Excel Online straight out of Visual Studio.

If you’re interested in launching your Office Add-in in any of the other Office Online applications, have a look here:
http://simonjager.com/office-add-ins-launch-in-office-online/

1. Get yourself an Office 365 tenant. If you don’t already have one, I would advise you to look into the Office 365 Developer Program:
http://dev.office.com/devprogram

2. Locate the URL of your Sharepoint site. This will be required by Visual Studio when uploading the Office Add-in manifest to your Office 365 tenant.

1

3. Head over to your Office Add-in solution in Visual Studio and get into the properties of the manifest project. Configure the Start Action to be a web browser instead of “Office Desktop Client”. Make sure to enter your Sharepoint site URL in the Site URL field.

2

At this point you will be asked to sign in with a user belonging to this Office 365 tenant. Make sure that this user has access to your Sharepoint site.

4. Before you can upload and launch your Office Add-in you’ll need to make sure that app side-loading is enabled for your Sharepoint site. By default it is not, and you will have to enable it using the SharePoint Online Management Shell. Download and install it:
http://www.microsoft.com/en-us/download/details.aspx?id=35588

5. Save and run the following PowerShell script (reference: http://blogs.msdn.com/b/officeapps/archive/2013/12/10/enable-app-sideloading-in-your-non-developer-site-collection.aspx) in order to enable app side-loading for your Sharepoint site. Read more about enabling/disabling app side-loading and the risks associated with it at the link above.

$programFiles = [environment]::getfolderpath("programfiles")

add-type -Path $programFiles'\SharePoint Online Management Shell\' + <code>
  'Microsoft.Online.SharePoint.PowerShell\Microsoft.SharePoint.Client.dll'

Write-Host </code>
  'To enable SharePoint app sideLoading, ' + <code>
  'enter Site Url, username and password'

$siteurl = Read-Host 'Site Url'
$username = Read-Host &quot;User Name&quot;
$password = Read-Host -AsSecureString 'Password'

if ($siteurl -eq '') {
    $siteurl = 'https://mytenant.sharepoint.com/sites/mysite'
    $username = 'me@mytenant.onmicrosoft.com'
    $password = ConvertTo-SecureString -String 'mypassword!'</code>
                -AsPlainText -Force
}
$outfilepath = $siteurl -replace ':', '_' -replace '/', '_'

try
{
    [Microsoft.SharePoint.Client.ClientContext]$cc = <code>
      New-Object Microsoft.SharePoint.Client.ClientContext($siteurl)

    [Microsoft.SharePoint.Client.SharePointOnlineCredentials]$spocreds = </code>
      New-Object <code>
      Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, </code>
      $password)

    $cc.Credentials = $spocreds
    $sideLoadingEnabled = <code>
    [Microsoft.SharePoint.Client.appcatalog]::IsAppSideloadingEnabled($cc);

    $cc.ExecuteQuery()

    if($sideLoadingEnabled.value -eq $false) {
        Write-Host -ForegroundColor Yellow </code>
          'SideLoading feature is not enabled on the site:' $siteurl
        $site = $cc.Site;
            $sideLoadingGuid = <code>
           new-object System.Guid &quot;AE3A1339-61F5-4f8f-81A7-ABD2DA956A7D&quot;
            $site.Features.Add($sideLoadingGuid, $false, </code>
            [Microsoft.SharePoint.Client.FeatureDefinitionScope]::None);
            $cc.ExecuteQuery();
           Write-Host -ForegroundColor Green <code>
          'SideLoading feature enabled on site' $siteurl
    }

    Else {
        Write-Host -ForegroundColor Green </code>
          'SideLoading feature is already enabled on site' $siteurl
    }
}

Catch {
    Write-Host -ForegroundColor Red <code>
      'Error encountered when trying to enable SideLoading feature' </code>
      $siteurl, ':' $Error[0].ToString();
}

6. Now run your Office Add-in and experience it in the online world of Office! If Visual Studio doesn’t open your selected web browser – you can look into the build output and find the Office Add-in URL. Copy it and navigate to it in your web browser to get going!

3

-Simon Jäger