3

We have a requirement to use the site Template for creating new sites using web provisioning and add related Add-In in the generated sites. We have a problem while adding an Add-in (.SPFX App) to the new sites. We are using the Latest SharePoint framework to design the Add-In.

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);
    }

We tried the following scenarios to achieve this.

1) When trying to install the app programmatically we get the following error

"Value cannot be null. Parameter name: xeAppPermissionRequests."

2) When trying to install the app (.spapp format) programmatically we get the following error.

"Clientside solutions are not allowed"

3) We tried to install the app using the AppStapling method, we get the following error.

"Sorry, something went wrong An unexpected error has occurred. "

4) While adding the app manually(using add an app) We were able to install the app in the site without any issue. But couldn't save the same site as Template.

We are on a Tight schedule. Any Help at the earliest is appreciated.

Thanks in Advance.

  • Any solution for this? We also need to copy a SPFX solution to a new site when the site is provisioned but can't figure out a way to do it. It doesn't come over property when we use the PnP provisioning engine to create the site and the LoadAndInstallApp doesn't work because its not really an "add-in". – Eric Gregorich May 31 '17 at 12:41
3

There is a difference between add-ins and SPFX. And SPFX solution is not an add-in. They share many parts (load in the app catalog, activate on a site, etc.) but they have differences (no AppPermissions, etc.)

3

Please look at this tip: https://www.codeproject.com/Tips/1224160/Deploy-an-SpFX-sppkg-file-add-in-via-CSOM-to-on-pr Title of the article is "Deploy an SpFX (.sppkg file) add-in via CSOM to on-premise SP2016" It solves the issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.