O is actually quite simple and ugly.
The application in SharePoint 2013 is actually a compressed package based on openxml. You can change the Suffix from app to zip, and then you can see the structure in it.
There are three main files: appmanifest.xml?appicon.png=appicon.png. config. xml. Through openxml tools, you can also view the relationships between them ).
Then it's easy. First create an appdefinition class that can be serialized into XML format (the class here is the simplest, that is, it does not contain permissions and other information ). If you want to be more professional, you can generate an appdefinition Class Based on XML schema definition (XSD) in SharePoint app manifest (schema map) for serialization.
[XmlRoot("App", Namespace = "http://schemas.microsoft.com/sharepoint/2012/app/manifest")]public class AppDefinition { [XmlAttribute("Name")] public string Name { get; set; } [XmlAttribute("ProductID")] public string ProductID { get; set; } [XmlAttribute("Version")] public string Version { get; set; } [XmlAttribute("SharePointMinVersion")] public string SharePointMinVersion { get; set; } [XmlElement] public AppProperties Properties { get; set; } [XmlElement(ElementName = "AppPrincipal")] public AppPrincipal Principal { get; set; } [XmlRoot] public class AppProperties { [XmlElement] public string Title { get; set; } [XmlElement] public string StartPage { get; set; } } [XmlRoot] public class AppPrincipal { [XmlElement] public RemoteWebApplication RemoteWebApplication { get; set; } } [XmlRoot] public class RemoteWebApplication { [XmlAttribute("ClientId")] public string ClientId { get; set; } }}
Then, xmlserializer can be used to serialize the instantiated appdefinition (Definition) to appmanifest. xml.
AppDefinition definition = new AppDefinition() { Name = Guid.NewGuid().ToString(), ProductID = Guid.NewGuid().ToString("B"), Version = "1.0.0.0", SharePointMinVersion = "15.0.0.0", Properties = new AppDefinition.AppProperties() { Title = title, StartPage = launchUrl }, Principal = new AppDefinition.AppPrincipal { RemoteWebApplication = new AppDefinition.RemoteWebApplication { ClientId = Guid.NewGuid().ToString("B"), } }};
using (XmlWriter writer = XmlTextWriter.Create(partStream, new XmlWriterSettings() { Encoding = Encoding.UTF8, Indent = true })) { XmlSerializer serializer = new XmlSerializer(typeof(AppDefinition)); serializer.Serialize(writer, definition);}
Finally, use the package class under system. Io. packaging to package.
using (Package package = Package.Open(stream, FileMode.Create)) { PackagePart manifestPart = package.CreatePart<AppDefinition>(new Uri("/AppManifest.xml", UriKind.Relative), "text/xml", definition); PackagePart iconPart = package.CreatePart<string>(new Uri("/AppIcon.png", UriKind.Relative), "application/wsp", path); PackagePart configPart = package.CreatePart<AppPartConfig>(new Uri("/AppIcon.png.config.xml", UriKind.Relative), "text/xml", config); package.CreateRelationship(manifestPart.Uri, TargetMode.Internal, "http://schemas.microsoft.com/sharepoint/2012/app/relationships/package-manifest"); manifestPart.CreateRelationship(iconPart.Uri, TargetMode.Internal, "http://schemas.microsoft.com/sharepoint/2012/app/relationships/manifest-icon"); iconPart.CreateRelationship(configPart.Uri, TargetMode.Internal, "http://schemas.microsoft.com/sharepoint/2012/app/relationships/partconfiguration");}
O (distinct _ distinct) O ~~ If you can understand and use it, take it for fun. Download the sample code here.
See:
Using e the app manifest and the package of an app for Sharepoint
How to package an application in SharePoint 2013