private void PopulateOptionalAppxPackagesAndBundles()

in AppInstallerFileBuilder/AppInstallerFileBuilderLib/AppxPackaging/AppxBundleMetadata.cs [185:225]


        private void PopulateOptionalAppxPackagesAndBundles()
        {
            IAppxBundleManifestReader2 bundleManifestReader2 = (IAppxBundleManifestReader2)this.manifestReader;

            // Iterate over all OptionalBundle elements in the manifest
            IAppxBundleManifestOptionalBundleInfoEnumerator optionalBundlesEnumerator = bundleManifestReader2.GetOptionalBundles();
            while (optionalBundlesEnumerator.GetHasCurrent())
            {
                IAppxBundleManifestOptionalBundleInfo optionalBundleInfo = optionalBundlesEnumerator.GetCurrent();

                if (optionalBundleInfo.GetFileName() != null)
                {
                    // If the file name of the OptionalBundle is not null, it points to a physical optional package bundle, in which
                    // case we recursively create the bundle info for the optional bundle.
                    this.OptionalAppxBundles.Add(new ExternalPackageReference(
                        this,
                        optionalBundleInfo.GetPackageId().GetPackageFullName(),
                        optionalBundleInfo.GetFileName(),
                        isOptional: true));
                }
                else
                {
                    // Otherwise, the PackageInfo child elements of the OptionalBundle element point to the optional appx packages.
                    IAppxBundleManifestPackageInfoEnumerator optionalPackagesEnumerator = optionalBundleInfo.GetPackageInfoItems();

                    while (optionalPackagesEnumerator.GetHasCurrent())
                    {
                        IAppxBundleManifestPackageInfo optionalPackageInfo = optionalPackagesEnumerator.GetCurrent();
                        this.OptionalAppxPackages.Add(new ExternalPackageReference(
                            this,
                            optionalPackageInfo.GetPackageId().GetPackageFullName(),
                            optionalPackageInfo.GetFileName(),
                            isOptional: true));

                        optionalPackagesEnumerator.MoveNext();
                    }
                }

                optionalBundlesEnumerator.MoveNext();
            }
        }