In this blog, we will look at steps to install and deploy SharePoint apps to Modern Sites using SharePoint ALM CSOM and PnP PowerShell. Using the below steps, it is possible to programmatically deploy and install custom SharePoint Framework apps using an Azure Function or a Local PowerShell script.
Installing SharePoint Apps
SharePoint Apps can be deployed on a site using ALM (Application Lifecycle Management) APIs. After the app is installed in the App catalog, we could add it to a SharePoint site.
SharePoint CSOM
The steps are simple. The below snippet has the code for deploying and installing apps.
1. Get the App Id
2. Create an App Manager Object
3. Deploy the App
4. After deploy the app, install the app.
5. Use Try – catch to handle if the installation has already done
PnP PowerShell
First, lets’ get a list of apps in the App catalog.
Note: There are two values that is supported by scope paramaters for Apps – Tenant and Site.
Get-PnPApp -Scope Tenant or Get-PnPApp -Scope Site
If the App is not installed, then we will add the app to the App catalog
Add-PnPApp -Path "<.sppkg file location>" -Scope Site
Then, publish the App
Publish-PnPApp -Identity -Scope Tenant -SkipFeatureDeployment
-SkipFeatureDeployment is helpful to deploy Apps across the SharePoint tenancy if the app is developed for tenant wide deployments
After the above, we will install the App
Install-PnPApp -Identity -Scope Site
After the app is installed, it is ready to be added or used at the site.
In the upcoming blog, we will see how to add SharePoint Framework extensions and web parts programmatically.
Happy Coding!!
Hi Asish,
Thank you for the great blog. One quick question while installing the app? In my case, i want to skip the app installation in a site if the app is already installed. It looks like, there is no direct way to skip the installation if the app exists? Is catching via exception is the only way to know?
Thanks!
Ravi