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 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); }
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); }