NuGet.Commands.ProjectFactory.ProcessDependencies C# (CSharp) Method

ProcessDependencies() private method

private ProcessDependencies ( PackageBuilder builder ) : void
builder PackageBuilder
return void
        private void ProcessDependencies(PackageBuilder builder)
        {
            string packagesConfig = GetPackagesConfig();

            // No packages config then bail out
            if (String.IsNullOrEmpty(packagesConfig))
            {
                return;
            }

            Logger.Log(MessageLevel.Info, NuGetResources.UsingPackagesConfigForDependencies);

            var file = new PackageReferenceFile(packagesConfig);

            // Get the solution repository
            IPackageRepository repository = GetPackagesRepository();

            // Collect all packages
            var packages = new List<IPackage>();

            IDictionary<Tuple<string, SemanticVersion>, PackageReference> packageReferences = file.GetPackageReferences()
                                                                                          .ToDictionary(r => Tuple.Create(r.Id, r.Version));

            foreach (PackageReference reference in packageReferences.Values)
            {
                if (repository != null)
                {
                    IPackage package = repository.FindPackage(reference.Id, reference.Version);
                    if (package != null)
                    {
                        packages.Add(package);
                    }
                }
            }

            // Add the transform file to the package builder
            ProcessTransformFiles(builder, packages.SelectMany(GetTransformFiles));

            var dependencies = builder.GetCompatiblePackageDependencies(targetFramework: null)
                                      .ToDictionary(d => d.Id, StringComparer.OrdinalIgnoreCase);

            // Reduce the set of packages we want to include as dependencies to the minimal set.
            // Normally, packages.config has the full closure included, we only add top level
            // packages, i.e. packages with in-degree 0
            foreach (var package in GetMinimumSet(packages))
            {
                // Don't add duplicate dependencies
                if (dependencies.ContainsKey(package.Id))
                {
                    continue;
                }

                IVersionSpec spec = GetVersionConstraint(packageReferences, package);
                var dependency = new PackageDependency(package.Id, spec);
                dependencies[dependency.Id] = dependency;
            }

            // TO FIX: when we persist the target framework into packages.config file, 
            // we need to pull that info into building the PackageDependencySet object
            builder.DependencySets.Clear();
            builder.DependencySets.Add(new PackageDependencySet(null, dependencies.Values));
        }