/// <summary>
        /// A package is deemed to be a satellite package if it has a language property set, the id of the package is
        /// of the format [.*].[Language]
        /// and it has at least one dependency with an id that maps to the runtime package .
        /// </summary>
        public static bool IsSatellitePackage(IPackageCoreReader packageReader, out PackageIdentity runtimePackageIdentity, out string packageLanguage)
        {
            // A satellite package has the following properties:
            //     1) A package suffix that matches the package's language, with a dot preceding it
            //     2) A dependency on the package with the same Id minus the language suffix
            //     3) The dependency can be found by Id in the repository (as its path is needed for installation)
            // Example: foo.ja-jp, with a dependency on foo

            var nuspecReader = new NuspecReader(packageReader.GetNuspec());
            var packageId    = nuspecReader.GetId();

            packageLanguage = nuspecReader.GetLanguage();
            string localruntimePackageId = null;

            if (!String.IsNullOrEmpty(packageLanguage)
                &&
                packageId.EndsWith('.' + packageLanguage, StringComparison.OrdinalIgnoreCase))
            {
                // The satellite pack's Id is of the format <Core-Package-Id>.<Language>. Extract the core package id using this.
                // Additionally satellite packages have a strict dependency on the core package
                localruntimePackageId = packageId.Substring(0, packageId.Length - packageLanguage.Length - 1);

                foreach (var group in nuspecReader.GetDependencyGroups())
                {
                    foreach (var dependencyPackage in group.Packages)
                    {
                        if (dependencyPackage.Id.Equals(localruntimePackageId, StringComparison.OrdinalIgnoreCase) &&
                            dependencyPackage.VersionRange != null &&
                            dependencyPackage.VersionRange.MaxVersion == dependencyPackage.VersionRange.MinVersion &&
                            dependencyPackage.VersionRange.IsMaxInclusive &&
                            dependencyPackage.VersionRange.IsMinInclusive)
                        {
                            var runtimePackageVersion = new NuGetVersion(dependencyPackage.VersionRange.MinVersion.ToNormalizedString());
                            runtimePackageIdentity = new PackageIdentity(dependencyPackage.Id, runtimePackageVersion);
                            return(true);
                        }
                    }
                }
            }

            runtimePackageIdentity = null;
            return(false);
        }
Ejemplo n.º 2
0
        public static Manifest GetManifest(this IPackageCoreReader packageReader)
        {
            using (var stream = packageReader.GetNuspec())
            {
                var manifest = Manifest.ReadFrom(stream, true);
                manifest.Files.AddRange(packageReader.GetFiles()
                                        // Skip the auto-added stuff
                                        .Where(file =>
                                               file != "[Content_Types].xml" &&
                                               file != "_rels/.rels" &&
                                               !file.EndsWith(".nuspec") &&
                                               !file.EndsWith(".psmdcp"))
                                        .Select(file => new ManifestFile
                {
                    // Can't replicate the Source path as it was originally before adding
                    // to the package, so leave it null to avoid false promises in tests.
                    //Source = file.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar),
                    Target = file.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar)
                }));

                return(manifest);
            }
        }
Ejemplo n.º 3
0
 public Stream GetNuspec() => _reader.GetNuspec();