public static PackagePart CreateAppManifest(this Package package, Guid productId, Guid identifier, string title, string launchUrl) {
            AppManifest o = new AppManifest() {
                Name = Guid.NewGuid().ToString(),
                ProductID = productId,
                Version = "1.0.0.0",
                SharePointMinVersion = "15.0.0.0",
                Properties = new AppManifest.AppProperties() {
                    Title = title,
                    LaunchUrl = launchUrl
                },
                Principal = new AppManifest.AppPrincipal {
                    RemoteWebApplication = new AppManifest.RemoteWebApplication {
                        ClientId = identifier
                    }
                }
            };

            Uri partUri = new Uri("/AppManifest.xml", UriKind.Relative);
            string contentType = "text/xml";
            PackagePart part = package.CreatePart(partUri, contentType);
            using (Stream stream = part.GetStream(FileMode.Create, FileAccess.Write))
            using (XmlWriter writer = XmlTextWriter.Create(stream)) {
                XmlSerializer serializer = new XmlSerializer(typeof(AppManifest));
                XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();
                namespaces.Add("", "http://schemas.microsoft.com/sharepoint/2012/app/manifest");
                serializer.Serialize(writer, o, namespaces);
            }
            return part;
        }
 public static PackagePart CreateAppIcon(this Package package, MemoryStream imageStream) {
     Uri partUri = new Uri("/AppIcon.png", UriKind.Relative);
     string contentType = "application/wsp";
     PackagePart part = package.CreatePart(partUri, contentType);
     using (Stream stream = part.GetStream(FileMode.Create, FileAccess.Write)) {
         using (BinaryWriter writer = new BinaryWriter(stream)) {
             writer.Write(imageStream.ToArray());
         }
     }
     return part;
 }
 public static PackagePart CreateAppIconConfig(this Package package) {
     AppPartConfig o = new AppPartConfig() {
         Id = Guid.NewGuid().ToString()
     };
     Uri partUri = new Uri("/AppIcon.png.config.xml", UriKind.Relative);
     string contentType = "text/xml";
     PackagePart part = package.CreatePart(partUri, contentType);
     using (Stream stream = part.GetStream(FileMode.Create, FileAccess.Write))
     using (XmlWriter writer = XmlTextWriter.Create(stream)) {
         XmlSerializer serializer = new XmlSerializer(typeof(AppPartConfig));
         XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();
         namespaces.Add("", "http://schemas.microsoft.com/sharepoint/2012/app/partconfiguration");
         serializer.Serialize(writer, o, namespaces);
     }
     return part;
 }