Deploy SPFx solution in SharePoint online site collection scope only

Deploy SPFx solution in SharePoint online site collection scope only

No comments

 18,481 total views,  44 views today

As far as SharePoint is concerned, there are many hidden URLs, features are available both in SharePoint on pre-mise as well as SharePoint Online those actually will be hidden from the users – generally Power User access those hidden link by directly putting the URL into the browser or by activating some feature using the PowerShell or PnP PowerShell command. Coming to the main topic – as far as SharePoint Online is concerned, there is only one app catalog site collection in the tenant (at least this was my understanding) and per tenant, we can have only one tenant-level app catalog site collection. However, if we want to deploy the SPFx (SharePoint Framework) solution in a particular site collection scope, how to do it?  Well, in this article we will learn about how to deploy an SPFx (SharePoint Framework) solution in a particular site collection scope. I have written an article on how to create app catalog site collection at the tenant level – please read it from here – Create app catalog site in SharePoint online step by step

As per Microsoft about app catalog site collection:

 “You can have only one App Catalog site collection for your organization, and you only need to create it once.”

I think I am not convinced about the above Microsoft statement as we could create an app catalog site collection for each individual site collection.

Key-Highlights: What you will learn from this article

  • Challenges in tenant-level app catalog deployment scope
  • How to overcome the above challenge or deploy SPFx solution in site collection scope only?
  • Enable or add the app catalog feature in the site collection scope using the PowerShell script

Challenges in tenant-level app catalog deployment scope

If you have a SharePoint Online tenant which is used for development, test, and production purpose. Then, you are developing an SPFx solution for your client which is in progress (the functionality has not yet been completed) and in between a couple of times, you have deployed to the tenant level app catalog site collection for your testing purpose – you know what will happen now? This underdevelopment web part or SPFx solution will be available across the tenant from each site – behind the end-users will not get know about this, so they just try to add this under development web part into their pages since it will display in the web part gallery but in reality, this web part will not function – as a result, this will lead to customer dissatisfaction over the use of SharePoint Online – they will just think and comment “SharePoint is not working”.

The above scenario is one of the examples of having tenant-level app catalog scope enabled, however, there are many disadvantages like this.

How to overcome the above challenge or deploy SPFx solution in site collection scope only?

In order to overcome the above issue, we have to deploy the SPFx web part or solution in the site collection scope only – now we will learn how to deploy the SPFx solution to the site collection scope only.

We can activate the “appcatalog” for any site collection – the hidden formula is, we just need to append the URL with the “appcatalog” text, I mean we need to add the “appcatalog” text to the after the site name.

For example “https://globalsharepoint2020.sharepoint.com/sites/TestCommSite2/appcatalog” – here before the ‘/appcatalog’ is my site URL.

Now, let’s access the above URL, we will see the below “404 NOT FOUND” because we are trying to access the “appcatalog” site collection URL but the “appcatalog” has not been enabled yet in this site collection.

404 not found error in site collection scope appcatalog - SPFx solution deployment
404 not found error in site collection scope appcatalog – SPFx solution deployment

Now, we will execute the below PowerShell script to enable the ‘appcatalog’ in the site collection scope only.

Enable or add the app catalog feature in the site collection scope using the PowerShell script

Using the below PowerShell script we can enable or add the app catalog feature in the site collection scope:


####The below script will activate or remove app catalog site collection in the site collection level only.

cls

$PSshell = Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorVariable err -ErrorAction SilentlyContinue
if($PSshell -eq $null)
{
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}

$fileName = "Adding-Removing app catalog in SPO site collection scope"

#'yyyyMMddhhmm yyyyMMdd
$enddate = (Get-Date).tostring("yyyyMMddhhmmss")
#$filename = $enddate + '_VMReport.doc'
$logFileName = $fileName +"_"+ $enddate+"_Log.txt"
$invocation = (Get-Variable MyInvocation).Value
$directoryPath = Split-Path $invocation.MyCommand.Path

$directoryPathForLog=$directoryPath+"\"+"LogFiles"
if(!(Test-Path -path $directoryPathForLog))
{
New-Item -ItemType directory -Path $directoryPathForLog
#Write-Host "Please Provide Proper Log Path" -ForegroundColor Red
}
#$logPath = $directoryPath + "\" + $logFileName

$logPath = $directoryPathForLog + "\" + $logFileName

$isLogFileCreated = $False

function Write-Log([string]$logMsg)
{
if(!$isLogFileCreated){
Write-Host "Creating Log File..."
if(!(Test-Path -path $directoryPath))
{
Write-Host "Please Provide Proper Log Path" -ForegroundColor Red
}
else
{
$script:isLogFileCreated = $True
Write-Host "Log File ($logFileName) Created..."
[string]$logMessage = [System.String]::Format("[$(Get-Date)] - {0}", $logMsg)
Add-Content -Path $logPath -Value $logMessage
}
}
else
{
[string]$logMessage = [System.String]::Format("[$(Get-Date)] - {0}", $logMsg)
Add-Content -Path $logPath -Value $logMessage
}
}

########################Adding-Removing app catalog site collection in Sharepoint Online site collection scope only##############################

#Paramaters area
$adminSiteURL="https://globalsharepoint2020-admin.sharepoint.com" #your admin center URL
$siteURL="https://globalsharepoint2020.sharepoint.com/sites/TestCommSite2" #Your site collection URL
$userName = "YourSPOOnlineUser@yourtenant.com"
$passWord = "Your_SPO_Password"
$encPassWord = convertto-securestring -String $passWord -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $userName, $encPassWord
#Paramaters area - Ends

Try
{
Connect-SPOService -Url $adminSiteURL -Credential $cred

$site = Get-SPOSite $siteURL

################Adding app catalog in site collection scope ##############

#The app catalog site collection is being enabled in site collection scope.
Write-host -f Yellow "Creating site collection app catalog in: "$SiteURL

Add-SPOSiteCollectionAppCatalog -Site $site

Write-host -f Green "Created site collection app catalog in!" $SiteURL

################Adding app catalog in site collection scope - ends here ####


############Disabling the site collection app catalog#######################

#The app catalog site collection is being disabled in site collection scope.

Write-host -f Yellow "Disabling site collection app catalog in: "$SiteURL

#Remove-SPOSiteCollectionAppCatalog -Site $site

Write-host -f Yellow "Disabled site collection app catalog in: "$SiteURL

############Disabling the site collection app catalog - ends here#############

}
Catch
{

$ErrorMessage = $_.Exception.Message +"in adding or removing app catalog site collection in site collection scope only!:"
Write-Host $ErrorMessage -BackgroundColor Red
Write-Log $ErrorMessage

}

########################Adding-Removing app catalog site collection in Sharepoint Online site collection scope only - Ends here ##############################

 

After executing the above PowerShell script, let’s browse the same URL – “https://globalsharepoint2020.sharepoint.com/sites/TestCommSite2/appcatalog“, we can see that the ‘AppCatalog’ URL is accessible now, and also we could see the “Apps for SharePoint” library is visible where we have to upload the SPFx .sppkg file.

Apps for SharePoint library for SPFx SharePoint Online Site collection scope
Apps for SharePoint library for SPFx SharePoint Online Site collection scope

Summary: What we had here?

Thus, in this article, we have learned how to deploy the SPFx framework solution to SharePoint site collection scope only. We can summarize our learning as below:

  • Enable or add the app catalog feature in the site collection scope using the PowerShell script.
  • How to deploy the SPFx framework solution to SharePoint site collection scope only.
  • The disadvantage of tenant-level SPFx deployment scope.
  • How to add app catalog site collection using the “Add-SPOSiteCollectionAppCatalog” PowerShell command
  • How to remove app catalog site collection using the “Remove-SPOSiteCollectionAppCatalog” PowerShell command

See Also:

You may also like the following SharePoint PowerShell tutorials:

Hope you have enjoyed reading this article and helped you. If you like to appreciate our efforts, please do share this with your friends and colleagues. 🙂

Download SharePoint Online & Office 365 Administration eBook

Buy the premium version of SharePoint Online & Office 365 administration eBook from here:



Buy SharePoint Online & Office 365 Administration eBook


 

Get the free demo PDF eBook from here:

FREE DOWNLOAD

Send download link to:

Subscribe to get exclusive content and recommendations every month. You can unsubscribe anytime.