コード例 #1
0
        /// <summary>
        /// Warn for dependencies that have been bumped up.
        /// </summary>
        public static IEnumerable <RestoreLogMessage> GetBumpedUpDependencies(
            List <IndexedRestoreTargetGraph> graphs,
            PackageSpec project,
            ISet <string> ignoreIds)
        {
            var messages = new List <RestoreLogMessage>();

            // Group by framework to get project dependencies, then check each graph.
            foreach (var frameworkGroup in graphs.GroupBy(e => e.Graph.Framework))
            {
                // Get dependencies from the project
                var dependencies = project.GetPackageDependenciesForFramework(frameworkGroup.Key)
                                   .Where(e => !ignoreIds.Contains(e.Name, StringComparer.OrdinalIgnoreCase))
                                   .Where(IsNonFloatingPackageDependency);

                foreach (var dependency in dependencies)
                {
                    // Graphs may have different versions of the resolved package
                    foreach (var indexedGraph in frameworkGroup)
                    {
                        var minVersion = dependency.LibraryRange.VersionRange?.MinVersion;
                        if (minVersion != null && dependency.LibraryRange.VersionRange.IsMinInclusive)
                        {
                            // Ignore floating or version-less (project) dependencies
                            // Avoid warnings for non-packages
                            var match = indexedGraph.GetItemById(dependency.Name, LibraryType.Package);

                            if (match != null && match.Key.Version > minVersion)
                            {
                                var message = string.Format(CultureInfo.CurrentCulture, Strings.Log_DependencyBumpedUp,
                                                            dependency.LibraryRange.Name,
                                                            dependency.LibraryRange.VersionRange.PrettyPrint(),
                                                            match.Key.Name,
                                                            match.Key.Version);

                                var graphName = indexedGraph.Graph.TargetGraphName;

                                messages.Add(RestoreLogMessage.CreateWarning(NuGetLogCode.NU1601, message, match.Key.Name, graphName));
                            }
                        }
                    }
                }
            }

            return(messages);
        }