protected override async Task <int> ExecuteOnManifest(XDocument document) { var action = new SetPackageProperties { Logo = this.Verb.Logo, Description = this.Verb.Description, DisplayName = this.Verb.DisplayName, ModificationPackage = this.Verb.ModificationPackage, PublisherDisplayName = this.Verb.PublisherDisplayName }; var actionExecutor = new SetPackagePropertiesExecutor(document); actionExecutor.ValueChanged += (_, changed) => { if (string.IsNullOrEmpty(changed.OldValue) || string.Equals(changed.OldValue, changed.NewValue)) { this.Console.WriteSuccess($"Set property '{changed.Key}' to '{changed.NewValue}'.").GetAwaiter().GetResult(); } else { this.Console.WriteSuccess($"Changed property '{changed.Key}' from '{changed.OldValue}' to '{changed.NewValue}'.").GetAwaiter().GetResult(); } }; await actionExecutor.Execute(action, CancellationToken.None).ConfigureAwait(false); return(StandardExitCodes.ErrorSuccess); }
private async Task PrepareModificationPackage(XDocument template, ModificationPackageConfig config) { XNamespace nsUap4 = "http://schemas.microsoft.com/appx/manifest/uap/windows10/4"; XNamespace nsUap6 = "http://schemas.microsoft.com/appx/manifest/uap/windows10/6"; XNamespace nsRescap = "http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"; XNamespace nsRescap6 = "http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities/6"; XNamespace nsBuild = "http://schemas.microsoft.com/developer/appx/2015/build"; XNamespace defaultNamespace = "http://schemas.microsoft.com/appx/manifest/foundation/windows10"; var root = template.Root; if (root == null) { root = new XElement(defaultNamespace + "Package"); template.Add(root); } else { defaultNamespace = root.GetDefaultNamespace(); } if (root.GetPrefixOfNamespace(nsUap4) == null) { root.Add(new XAttribute(XNamespace.Xmlns + "uap4", nsUap6.NamespaceName)); } if (root.GetPrefixOfNamespace(nsUap6) == null) { root.Add(new XAttribute(XNamespace.Xmlns + "uap6", nsUap6.NamespaceName)); } if (root.GetPrefixOfNamespace(nsRescap) == null) { root.Add(new XAttribute(XNamespace.Xmlns + "rescap", nsRescap.NamespaceName)); } if (root.GetPrefixOfNamespace(nsRescap6) == null) { root.Add(new XAttribute(XNamespace.Xmlns + "rescap6", nsRescap6.NamespaceName)); } if (root.GetPrefixOfNamespace(nsBuild) == null) { root.Add(new XAttribute(XNamespace.Xmlns + "build", nsBuild.NamespaceName)); } var package = GetOrCreateNode(template, "Package", defaultNamespace); var dependencies = GetOrCreateNode(package, "Dependencies", defaultNamespace); var dependency = new XElement(nsUap4 + "MainPackageDependency"); dependencies.Add(dependency); var parentName = config.ParentName; var parentPublisher = config.ParentPublisher; if (string.IsNullOrEmpty(parentPublisher) || string.IsNullOrEmpty(parentName)) { IAppxFileReader reader = null; try { if (string.Equals(FileConstants.AppxManifestFile, Path.GetFileName(config.ParentPackagePath), StringComparison.OrdinalIgnoreCase)) { reader = new FileInfoFileReaderAdapter(config.ParentPackagePath); } else { reader = new ZipArchiveFileReaderAdapter(config.ParentPackagePath); } var manifestReader = new AppxManifestReader(); var read = await manifestReader.Read(reader).ConfigureAwait(false); if (string.IsNullOrEmpty(parentPublisher)) { parentPublisher = read.Publisher; } if (string.IsNullOrEmpty(parentName)) { parentName = read.Name; } } finally { reader?.Dispose(); } } dependency.SetAttributeValue("Name", parentName); dependency.SetAttributeValue("Publisher", parentPublisher); var fixVersion = Version.Parse(config.Version); var major = fixVersion.Major; var minor = fixVersion.Minor; var build = fixVersion.Build; var revision = fixVersion.Revision; if (major < 0) { throw new FormatException("Invalid version format, major version is required."); } if (minor < 0) { throw new FormatException("Invalid version format, major version is required."); } if (revision < 0) { revision = 0; } if (build < 0) { build = 0; } // Set identity var setIdentity = new SetPackageIdentity { Name = config.Name, Publisher = config.Publisher, Version = new Version(major, minor, build, revision).ToString() }; await new SetPackageIdentityExecutor(template).Execute(setIdentity).ConfigureAwait(false); // Set properties var setProperties = new SetPackageProperties { DisplayName = config.DisplayName ?? "Modification Package Name", PublisherDisplayName = config.DisplayPublisher ?? "Modification Package Publisher Name", Description = "Modification Package for " + parentName, Logo = "Assets\\Logo.png", ModificationPackage = true }; await new SetPackagePropertiesExecutor(template).Execute(setProperties).ConfigureAwait(false); // Set build metadata var branding = new MsixHeroBrandingInjector(); await branding.Inject(template).ConfigureAwait(false); }