I am trying to install a SPFX(.sppkg) app while the site is generated. The site is created using Provider Hosted. The App was developed using CSOM and the site is developer Tenant site.
I am trying to add the app to the site using the following code
string path = @"~/App_Data/xxx.sppkg";
// Create context for SharePoint online
ClientContext ctx = new ClientContext(url);
ctx.AuthenticationMode = ClientAuthenticationMode.Default;
ctx.Credentials = new SharePointOnlineCredentials(userName, securePassword);
// Get variables for the operations
Site site = ctx.Site;
Web web = ctx.Web;
ctx.Load(site);
ctx.Load(web);
ctx.ExecuteQuery();
try
{
// Make sure we have side loading enabled.
// Using PnP Nuget package extensions.
site.Features.Add(sideloadingFeature,true,FeatureDefinitionScope.None);
try
{
string appFilePath = System.Web.Hosting.HostingEnvironment.MapPath(path);
// Load .app file and install that to site
var appstream = System.IO.File.OpenRead(appFilePath);
AppInstance app = web.LoadAndInstallApp(appstream);
ctx.Load(app);
ctx.ExecuteQuery();
}
catch(Exception ex)
{
Console.WriteLine(ex.ToString());
}
// Disable side loading feature using
// PnP Nuget package extensions.
site.Features.Remove(sideloadingFeature,true);
}
but when i tried the code above, I get the following error
"Value cannot be null.
Parameter name: xeAppPermissionRequests."
This issue occurs only when adding the app using Code.
Also we tried to add the app using the app stapling method, I get the following error.
"Sorry, something went wrong
An unexpected error has occurred."
While adding the app manually(using add an app) We were able to install the app without any issue.
But we have to do this in a programmatic way.
Is there any way to overcome this issue ? Please suggest.
Thanks in Advance
I am still stuck with this issue. Please help with a solution ASAP. I have a very tight deadline to complete this task.
Much Appreciated.
Thanks
As mentioned in the stackexchange thread, SPFX apps aren't add-ins, and you can't side load them, etc. They need to be installed in the tenant app catalog before they can be added to a site collection. @VesaJuvonen - is there a remote API for adding it to the site collection once this has happened?
@patmill we added the apps in App catalog site. And try to adding it in site collection using a remote receiver when a sub site was created.
@patmill - There's no API currently to deploy apps / SPFx packages from app catalog to sites. Only classic way to make this happen was through side loading with web.LoadAndInstallApp method. Since site level presentation of the web parts requires currently that sppkg is explicitly installed on the site, there's really no supported API to make this happen currently.
As @VesaJuvonen pointed out, the LoadAndInstallApp method will not work. We have a backlog item to add an API for deploy SPFx packages from app catalog to sites which will be tracked. I am closing this issue now and @MunojKannan in case there are more feature requests from your side, please use our UserVoice to post you requests. Here is the link : https://sharepoint.uservoice.com/forums/329220-sharepoint-dev-platform
If you want to install spfx web parts for on-prem too please take a look at my blog post -> https://rasper87.wordpress.com/2018/04/26/provision-spfx-web-parts-to-classic-sites-part-3-install-spfx-web-part-to-sharepoint-site-web/
Issues that have been closed & had no follow-up activity for at least 7 days are automatically locked. Please refer to our wiki for more details, including how to remediate this action if you feel this was done prematurely or in error: Issue List: Our approach to locked issues
Most helpful comment
If you want to install spfx web parts for on-prem too please take a look at my blog post -> https://rasper87.wordpress.com/2018/04/26/provision-spfx-web-parts-to-classic-sites-part-3-install-spfx-web-part-to-sharepoint-site-web/