Ejemplo n.º 1
0
        private void UpdateFromValues(PackageIndex index, string id, NuGetVersion version, IEnumerable <Version> assemblyVersions, IEnumerable <string> dllNames)
        {
            PackageInfo info = GetOrCreatePackageInfo(index, id);

            var packageVersion = VersionUtility.As3PartVersion(version.Version);

            // if we have a stable version, add it to the stable versions list
            if (!version.IsPrerelease)
            {
                info.StableVersions.Add(packageVersion);
            }

            var assmVersions = new HashSet <Version>(assemblyVersions.NullAsEmpty().Where(v => v != null));

            // add any new assembly versions
            info.AddAssemblyVersionsInPackage(assmVersions, packageVersion);

            // try to find an identity package to also add a mapping in the case this is a runtime package
            if (id.StartsWith("runtime."))
            {
                foreach (var dllName in dllNames)
                {
                    PackageInfo identityInfo;
                    if (index.Packages.TryGetValue(dllName, out identityInfo))
                    {
                        identityInfo.AddAssemblyVersionsInPackage(assmVersions, packageVersion);
                    }
                }
            }

            // remove any assembly mappings which claim to be in this package version, but aren't in the assemblyList
            var orphanedAssemblyVersions = info.AssemblyVersionInPackageVersion
                                           .Where(pair => pair.Value == packageVersion && !assmVersions.Contains(pair.Key))
                                           .Select(pair => pair.Key);

            if (orphanedAssemblyVersions.Any())
            {
                // make sure these aren't coming from a runtime package.
                var runtimeAssemblyVersions = index.Packages
                                              .Where(p => p.Key.StartsWith("runtime.") && p.Key.EndsWith(id))
                                              .SelectMany(p => p.Value.AssemblyVersionInPackageVersion)
                                              .Where(pair => pair.Value == packageVersion)
                                              .Select(pair => pair.Key);

                orphanedAssemblyVersions = orphanedAssemblyVersions.Except(runtimeAssemblyVersions);
            }

            foreach (var orphanedAssemblyVersion in orphanedAssemblyVersions.ToArray())
            {
                info.AssemblyVersionInPackageVersion.Remove(orphanedAssemblyVersion);
            }

            // if no assemblies are present in this package nor were ever present
            if (assmVersions.Count == 0 &&
                info.AssemblyVersionInPackageVersion.Count == 0)
            {
                // if in the native module map
                if (index.ModulesToPackages.Values.Any(p => p.Equals(id)))
                {
                    // ensure the baseline is set
                    info.BaselineVersion = packageVersion;
                }
            }
        }
Ejemplo n.º 2
0
        private void UpdateFromValues(PackageIndex index, string id, NuGetVersion version, IEnumerable <Version> assemblyVersions, IEnumerable <string> dllNames)
        {
            PackageInfo info = GetOrCreatePackageInfo(index, id);

            if (UpdateStablePackageInfo)
            {
                try
                {
                    IEnumerable <Version> allStableVersions = NuGetUtility.GetAllVersionsForPackageId(id, includePrerelease: false, includeUnlisted: false, Log, CancellationToken.None);
                    info.StableVersions.AddRange(allStableVersions);
                }
                catch (NuGetProtocolException)
                {
                    Log.LogWarning("Failed fetching stable nuget package versions from one or more of your feeds. Make sure you are connected to the internet and that all your feeds are reachable.");
                }
            }

            var packageVersion = VersionUtility.As3PartVersion(version.Version);

            // if we have a stable version, add it to the stable versions list
            if (!version.IsPrerelease)
            {
                info.StableVersions.Add(packageVersion);
            }

            var assmVersions = new HashSet <Version>(assemblyVersions.NullAsEmpty().Where(v => v != null));

            // add any new assembly versions
            info.AddAssemblyVersionsInPackage(assmVersions, packageVersion);

            // try to find an identity package to also add a mapping in the case this is a runtime package
            if (id.StartsWith("runtime."))
            {
                foreach (var dllName in dllNames)
                {
                    PackageInfo identityInfo;
                    if (index.Packages.TryGetValue(dllName, out identityInfo))
                    {
                        identityInfo.AddAssemblyVersionsInPackage(assmVersions, packageVersion);
                    }
                }
            }

            // remove any assembly mappings which claim to be in this package version, but aren't in the assemblyList
            var orphanedAssemblyVersions = info.AssemblyVersionInPackageVersion
                                           .Where(pair => pair.Value == packageVersion && !assmVersions.Contains(pair.Key))
                                           .Select(pair => pair.Key);

            if (orphanedAssemblyVersions.Any())
            {
                // make sure these aren't coming from a runtime package.
                var runtimeAssemblyVersions = index.Packages
                                              .Where(p => p.Key.StartsWith("runtime.") && p.Key.EndsWith(id))
                                              .SelectMany(p => p.Value.AssemblyVersionInPackageVersion)
                                              .Where(pair => pair.Value == packageVersion)
                                              .Select(pair => pair.Key);

                orphanedAssemblyVersions = orphanedAssemblyVersions.Except(runtimeAssemblyVersions);
            }

            foreach (var orphanedAssemblyVersion in orphanedAssemblyVersions.ToArray())
            {
                info.AssemblyVersionInPackageVersion.Remove(orphanedAssemblyVersion);
            }

            // if no assemblies are present in this package nor were ever present
            if (assmVersions.Count == 0 &&
                info.AssemblyVersionInPackageVersion.Count == 0)
            {
                // if in the native module map
                if (index.ModulesToPackages.Values.Any(p => p.Equals(id)))
                {
                    // ensure the baseline is set
                    info.BaselineVersion = packageVersion;
                }
            }
        }