In this blog, I will give you the list of steps to automate SharePoint ADD IN's deployment, using CSOM.

  1. ClientContext cctx = new ClientContext(myurl);
  2. cctx.AuthenticationMode = ClientAuthenticationMode.Default;
  3. cctx.Credentials = new SharePointOnlineCredentials(userName, pwd);
  4. // Get Site Information.
  5. Site site = cctx.Site;
  6. Web web = cctx.Web;
  7. try
  8. {
  9. site.ActivateFeature(sideloadingFeature);
  10. try
  11. {
  12. var appstream = System.IO.File.OpenRead(path);
  13. AppInstance app = web.LoadAndInstallApp(appstream);
  14. cctx.Load(app);
  15. cctx.ExecuteQuery();
  16. }
  17. catch
  18. {
  19. throw;
  20. }
  21. //Disable SideLoadingfeatures
  22. site.DeactivateFeature(sideloadingFeature);
  23. }
  24. catch (Exception ex)
  25. {
  26. Console.WriteLine(string.Format(“Exception!”), ex.ToString());
  27. Console.WriteLine(“Press any key to continue.”);
  28. Console.Read();
  29. }