CiprianoFreitas / SharePointAddInsWorkShop

Develop add-ins for SharePoint
MIT License
1 stars 1 forks source link

Sideloading not enabled - workarround #1

Open canoas opened 8 years ago

canoas commented 8 years ago

SharePoint Online: Sideloading of apps is not enabled on this site. http://www.superedge.net/2014/03/sideloading-of-apps-not-enabled-on-this.html

If you are deploying a solution to SharePoint Online, at some point you will likely come across the following error: Error occurred in deployment step 'Install app for SharePoint': Sideloading of apps is not enabled on this site.

So...In short, you will not be able to deploy any solution from Visual Studio to SharePoint Online/Office 365 without enabling Sideloading first. I will show you how to fix this and then explain later, so you don’t waste any time looking for the answer. After all, I believe you came here to find the fix firstSmile

2-Steps Solution: 1) Download and install SharePoint Online Management Shell
2) Execute the script below. (Note that the Sideloading Feature ID is harcoded in SharePoint, as are many other OOTB features)

$programFiles = [environment]::getfolderpath("programfiles")
add-type -Path $programFiles'\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.SharePoint.Client.dll'
Write-Host 'Ready to enable Sideloading'
$siteurl = Read-Host 'Site Url'
$username = Read-Host "User Name"
$password = Read-Host -AsSecureString 'Password'

$outfilepath = $siteurl -replace ':', '_' -replace '/', '_'

try
{
    [Microsoft.SharePoint.Client.ClientContext]$cc = New-Object Microsoft.SharePoint.Client.ClientContext($siteurl)
    [Microsoft.SharePoint.Client.SharePointOnlineCredentials]$spocreds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password)
    $cc.Credentials = $spocreds
    $site = $cc.Site;

    $sideLoadingGuid = new-object System.Guid "AE3A1339-61F5-4f8f-81A7-ABD2DA956A7D"
    $site.Features.Add($sideLoadingGuid, $true, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::None);

    $cc.ExecuteQuery();

    Write-Host -ForegroundColor Green 'SideLoading feature enabled on site' $siteurl
    #Activate the Developer Site feature
}
catch
{ 
    Write-Host -ForegroundColor Red 'Error encountered when trying to enable SideLoading feature' $siteurl, ':' $Error[0].ToString();
}

In your SPO Management Shell enter the url of the site you want to deploy the solution, the administrator username and the password. The powershell will take care of the rest.

enable-sideloading-sharepoint-online

Now off you go. You’re ready to deploy solutions from your Visual Studio straight into Office 365. You can also get a more elaborate code in the MSDN Code Solution Repository.