Deploy SPFx solution in SharePoint online site collection scope only

Site Collection App Catalog – How Do I Deploy SPFx in It?

No comments

Loading

Site Collection App Catalog: How to deploy SPFx solution in SharePoint online (site collection scoped app catalog) – 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. In this article, we will learn about how to deploy an SPFx (SharePoint Framework) solution in a particular site collection scope.

The thought behind the main topic is  – 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 an 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. Ok, let us first understand what App Catalogue site collection is in SharePoint Online. Then we will learn how to deploy the SPFx solution in the site collection app catalog.

What is App Catalog site collection in SharePoint Online?

The App Catalog site collection in SharePoint Online is a special site collection designed to store and manage custom apps for use within your SharePoint Online environment. It acts as a central repository for custom-developed apps and third-party apps that can be made available to users across the tenant or specific site collections.

Key Features of the App Catalog

  1. Centralized App Management
    • Provides a single location to upload, manage, and distribute custom SharePoint Framework (SPFx) solutions, SharePoint Add-ins, and Office Add-ins.
    • Ensures that all custom and third-party apps are centrally managed for better control and governance.
  2. Scoped Deployment
    • Apps in the App Catalog can be made available globally (tenant-wide) or restricted to specific site collections.
    • Facilitates targeted deployment, ensuring that only relevant apps are available to users in particular areas of the organization.
  3. Security and Compliance
    • Enables administrators to review and approve apps before they are made available to users.
    • Ensures that all apps meet organizational security and compliance requirements.
  4. Custom App Distribution
    • Allows for the distribution of internally developed custom apps that are tailored to meet specific business needs.
    • Supports the deployment of SPFx web parts, extensions, and other custom solutions.
  5. Version Management
    • Provides version control for apps, allowing administrators to update and manage different versions of apps.
    • Ensures that users have access to the latest features and security updates.

Setting Up the App Catalog

  1. Create the App Catalog Site Collection
    • To create an App Catalog, you need to be a SharePoint Online administrator.
    • Navigate to the SharePoint admin center and go to More features > Apps > App Catalog.
    • If the App Catalog site collection does not exist, you can create a new one by following the wizard.
  2. Upload Apps
    • Once the App Catalog site collection is created, navigate to the site.
    • You will find libraries for different types of apps: Apps for SharePoint, Apps for Office, and SPFx solutions.
    • Upload your custom or third-party app packages (.sppkg files for SPFx solutions, .app files for SharePoint Add-ins) to the appropriate library.
  3. Manage and Deploy Apps
    • After uploading an app, you can manage its properties, update it, or delete it from the App Catalog.
    • You can also specify which sites or site collections the app should be available to.

Benefits of Using the App Catalog

  1. Centralized Control
    • Provides a central point for managing all custom and third-party apps, ensuring consistent deployment and governance.
    • Facilitates better control over which apps are used within the organization.
  2. Improved Security
    • Allows administrators to vet and approve apps before they are deployed, reducing the risk of unauthorized or insecure apps being used.
    • Ensures compliance with organizational security policies.
  3. Ease of Distribution
    • Simplifies the process of distributing custom solutions across the organization.
    • Users can easily add approved apps to their sites from the Add an app interface in SharePoint.
  4. Enhanced Customization
    • Supports the deployment of custom solutions that enhance the functionality of SharePoint to meet specific business needs.
    • Enables developers to create and distribute apps tailored to the organization’s requirements.

Example Usage Scenario

Deploying a Custom SPFx Web Part

A development team creates a custom SharePoint Framework (SPFx) web part to display key performance indicators (KPIs) for the sales department. The steps to deploy this web part using the App Catalog are as follows:

  1. Package the Web Part: The development team packages the web part into a .sppkg file.
  2. Upload to App Catalog: An administrator uploads the .sppkg file to the Apps for SharePoint library in the App Catalog site collection.
  3. Deploy the App: The administrator deploys the web part, making it available to the Sales site collection.
  4. Add to Site: Users in the Sales department can now add the custom KPI web part to their site pages from the Add an app interface.

The App Catalog site collection in SharePoint Online is a crucial feature for managing and distributing custom and third-party apps across your SharePoint environment. It provides centralized control, enhances security, and simplifies the deployment process, ensuring that users have access to the necessary tools and solutions while maintaining governance and compliance. By leveraging the App Catalog, organizations can efficiently manage their app ecosystem and enhance their SharePoint Online functionality to meet specific business needs.

Tenant level App Catalog vs Site level App Catalog

In SharePoint Online, there are two types of App Catalogs: Tenant-level App Catalog and Site Collection-level App Catalog. Both serve the purpose of storing and managing custom apps, but they differ in scope, management, and use cases. Here’s a detailed comparison:

Tenant-level App Catalog

Key Features

  1. Scope
    • The Tenant-level App Catalog applies to the entire SharePoint Online tenant.
    • Apps uploaded to this catalog are available across all site collections within the tenant.
  2. Management
    • Managed by SharePoint Online administrators.
    • Provides centralized control over all custom and third-party apps for the organization.
  3. Deployment
    • Allows for the deployment of apps and customizations tenant-wide.
    • Useful for solutions that need to be available to all users and site collections.
  4. Governance and Compliance
    • Ensures that apps meet organizational standards and compliance requirements before deployment.
    • Centralized management helps maintain consistency and security across the tenant.

Use Cases

  • Organization-wide Customizations: When you need to deploy custom web parts, extensions, or applications that are used across multiple site collections.
  • Standardization: Ensuring all departments and teams use the same set of approved applications and customizations.
  • Enterprise Solutions: For solutions that need to be accessible to a broad user base within the organization.

Site Collection-level App Catalog

Key Features

  1. Scope
    • The Site Collection-level App Catalog is specific to a single site collection.
    • Apps uploaded to this catalog are only available within that specific site collection.
  2. Management
    • Managed by site collection administrators.
    • Provides more granular control, allowing individual site collection owners to manage their apps.
  3. Deployment
    • Apps and customizations can be deployed to meet the specific needs of a particular site collection.
    • Useful for departmental or team-specific solutions that do not need to be available tenant-wide.
  4. Governance and Compliance
    • Allows site collection administrators to manage apps relevant to their specific needs while still adhering to organizational policies.
    • Ensures that local requirements are met without impacting the entire tenant.

Use Cases

  • Departmental or Team Solutions: When specific departments or teams have unique requirements and need custom apps that are not relevant to the whole organization.
  • Project-specific Customizations: For project sites that require specific functionalities or tools that are not needed elsewhere.
  • Testing and Development: Allows for testing and deploying new apps in a controlled environment before considering tenant-wide deployment.

Comparison Summary

Feature Tenant-level App Catalog Site Collection-level App Catalog
Scope Tenant-wide Specific to one site collection
Management SharePoint Online administrators Site collection administrators
Deployment Apps available across all site collections Apps available within the specific site collection only
Use Cases Organization-wide customizations, standardization, enterprise solutions Departmental/team solutions, project-specific customizations, testing/development
Governance Centralized control and compliance Granular control with adherence to policies

Choosing the Right App Catalog

  • Tenant-level App Catalog: Choose this when you need to deploy apps that will be used across multiple site collections and when centralized management is crucial for maintaining consistency and security.
  • Site Collection-level App Catalog: Opt for this when specific site collections have unique requirements, when departmental autonomy is needed, or when testing new apps in a contained environment before wider deployment.

By understanding the differences between these two types of App Catalogs, organizations can better manage their custom and third-party apps, ensuring they meet both broad and specific needs within their SharePoint Online environment.

Deploy SPFx Solution in SharePoint online (Site collection scoped app Catalog)

  • Challenges in tenant-level app catalog deployment scope
  • How to overcome the above challenge or deploy the 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 (site collection scoped app catalog)

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 to this.

How to overcome the above challenge or deploy the SPFx solution in SharePoint Online 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, that we just need to append the URL with the “appcatalog” text, I mean we need to add the “appcatalog” text after the site name.

For example

 "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.

Deploy SPFx solution in SharePoint online, 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 (site collection scoped app catalog)

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="globalsharepoint2020-admin.sharepoint.com" #your admin center URL
$siteURL="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 below URL:

 "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, site collection scoped app catalog
Apps for SharePoint library for SPFx SharePoint Online Site collection scope

Summary: Site Collection scoped App Catalog

Thus, in this article, we have learned how to deploy the SPFx framework solution to the 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: SharePoint PowerShell Tutorials

You may also like the following SharePoint PowerShell tutorials:

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

 

 

 

About Post Author

Do you have a better solution or question on this topic? Please leave a comment