protected override async Task <int> ExecuteOnManifest(XDocument document) { var action = new SetPackageIdentity { Name = this.Verb.Name, ProcessorArchitecture = this.Verb.ProcessorArchitecture, Publisher = this.Verb.Publisher, Version = this.Verb.Version, ResourceId = this.Verb.ResourceId }; var actionExecutor = new SetPackageIdentityExecutor(document); actionExecutor.ValueChanged += (_, changed) => { if (string.IsNullOrEmpty(changed.OldValue) || string.Equals(changed.OldValue, changed.NewValue)) { this.Console.WriteSuccess($"Changed identity attribute '{changed.Key}' to '{changed.NewValue}'.").GetAwaiter().GetResult(); } else { this.Console.WriteSuccess($"Changed identity attribute '{changed.Key}' from '{changed.OldValue}' to '{changed.NewValue}'.").GetAwaiter().GetResult(); } }; await actionExecutor.Execute(action, CancellationToken.None).ConfigureAwait(false); return(StandardExitCodes.ErrorSuccess); }
private async Task AdjustManifest(XDocument template, AppxManifestCreatorOptions config, DirectoryInfo baseDirectory, string[] entryPoints) { XNamespace nsUap = "http://schemas.microsoft.com/appx/manifest/uap/windows10"; XNamespace nsUap4 = "http://schemas.microsoft.com/appx/manifest/uap/windows10/4"; XNamespace nsUap6 = "http://schemas.microsoft.com/appx/manifest/uap/windows10/6"; 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(); } // Add capability var addCapability = new AddCapability("runFullTrust"); var capabilityExecutor = new AddCapabilityExecutor(template); await capabilityExecutor.Execute(addCapability).ConfigureAwait(false); // Set identity var setIdentity = new SetPackageIdentity { Name = config.PackageName, Publisher = config.PublisherName, ProcessorArchitecture = config.PackageArchitecture.ToString("G").ToLowerInvariant() }; var major = config.Version.Major; var minor = config.Version.Minor; var build = config.Version.Build; var revision = config.Version.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; } setIdentity.Version = new Version(major, minor, build, revision).ToString(); var executor = new SetPackageIdentityExecutor(template); await executor.Execute(setIdentity).ConfigureAwait(false); // Add namespaces (legacy) if (root.GetPrefixOfNamespace(nsUap) == null) { root.Add(new XAttribute(XNamespace.Xmlns + "uap", nsUap.NamespaceName)); } 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)); } var package = GetOrCreateNode(template, "Package", defaultNamespace); var properties = GetOrCreateNode(package, "Properties", defaultNamespace); GetOrCreateNode(properties, "DisplayName", defaultNamespace).Value = config.PackageDisplayName ?? config.PackageName ?? "DisplayName"; GetOrCreateNode(properties, "Description", defaultNamespace).Value = config.PackageDisplayName ?? config.PackageName ?? "Description"; GetOrCreateNode(properties, "PublisherDisplayName", defaultNamespace).Value = config.PublisherDisplayName ?? config.PublisherName ?? "Publisher"; GetOrCreateNode(properties, "Logo", defaultNamespace).Value = "Assets\\Logo.png"; var applicationsNode = GetOrCreateNode(package, "Applications", defaultNamespace); var usedNames = new HashSet<string>(); foreach (var item in entryPoints) { var applicationNode = this.CreateApplicationNodeFromExe(baseDirectory, item); applicationsNode.Add(applicationNode); var idCandidate = Regex.Replace(Path.GetFileNameWithoutExtension(item), "[^a-zA-z0-9_]+", string.Empty); if (!usedNames.Add(idCandidate)) { var index = 1; var baseIdCandidate = idCandidate; while (!usedNames.Add(baseIdCandidate + "_" + index)) { index++; } idCandidate = baseIdCandidate + "_" + index; } applicationNode.SetAttributeValue("Id", idCandidate); } var branding = new MsixHeroBrandingInjector(); await branding.Inject(template, MsixHeroBrandingInjector.BrandingInjectorOverrideOption.PreferIncoming).ConfigureAwait(false); }