Example #1
0
        public void Add(NugetDependency packageDependency)
        {
            var package = nuget.FindBestPackage(packageDependency.Name, packageDependency.VersionRange);

            if (package == null)
            {
                var version = packageDependency.VersionRange.MinVersion.ToNormalizedString();
                Console.WriteLine($"Nuget was unable to find the package '{packageDependency.Name}' with version range '{packageDependency.VersionRange}', assuming it is using version '{version}'");
                builder.AddOrUpdatePackage(new Model.PackageId(packageDependency.Name, version));
                return;
            }

            var packageId = new Model.PackageId(packageDependency.Name, package.Identity.Version.ToNormalizedString());
            HashSet <Model.PackageId> dependencies = new HashSet <Model.PackageId>();

            var packages = nuget.DependenciesForPackage(package.Identity, packageDependency.Framework);

            foreach (PackageDependency dependency in packages)
            {
                var bestExisting = builder.GetBestVersion(dependency.Id, dependency.VersionRange);
                if (bestExisting != null)
                {
                    var id = new Model.PackageId(dependency.Id, bestExisting);
                    dependencies.Add(id);
                }
                else
                {
                    var depPackage = nuget.FindBestPackage(dependency.Id, dependency.VersionRange);
                    if (depPackage == null)
                    {
                        Console.WriteLine($"Unable to find package for '{dependency.Id}' version '{dependency.VersionRange}'");
                        continue;
                    }

                    var id = new Model.PackageId(depPackage.Identity.Id, depPackage.Identity.Version.ToNormalizedString());
                    dependencies.Add(id);

                    if (!builder.DoesPackageExist(id))
                    {
                        Add(new NugetDependency(dependency.Id, dependency.VersionRange, packageDependency.Framework));
                    }
                }
            }


            builder.AddOrUpdatePackage(packageId, dependencies);
        }
Example #2
0
        public DependencyResult Process()
        {
            var builder = new Model.PackageSetBuilder();
            var result  = new DependencyResult();

            foreach (var target in LockFile.Targets)
            {
                foreach (var library in target.Libraries)
                {
                    string name      = library.Name;
                    string version   = library.Version.ToNormalizedString();
                    var    packageId = new Model.PackageId(name, version);

                    HashSet <Model.PackageId> dependencies = new HashSet <Model.PackageId>();
                    foreach (var dep in library.Dependencies)
                    {
                        var id = dep.Id;
                        var vr = dep.VersionRange;
                        //vr.Float.FloatBehavior = NuGet.Versioning.NuGetVersionFloatBehavior.
                        var lb = target.Libraries;
                        var bs = BestVersion(id, vr, lb);
                        if (bs == null)
                        {
                            Console.WriteLine(dep.Id);
                            bs = BestVersion(id, vr, lb);
                        }
                        else
                        {
                            var depId = new Model.PackageId(id, bs.ToNormalizedString());
                            dependencies.Add(depId);
                        }
                    }

                    builder.AddOrUpdatePackage(packageId, dependencies);
                }
            }



            if (LockFile.PackageSpec.Dependencies.Count != 0)
            {
                foreach (var dep in LockFile.PackageSpec.Dependencies)
                {
                    var version = builder.GetBestVersion(dep.Name, dep.LibraryRange.VersionRange);
                    result.Dependencies.Add(new Model.PackageId(dep.Name, version));
                }
            }
            else
            {
                foreach (var framework in LockFile.PackageSpec.TargetFrameworks)
                {
                    foreach (var dep in framework.Dependencies)
                    {
                        var version = builder.GetBestVersion(dep.Name, dep.LibraryRange.VersionRange);
                        result.Dependencies.Add(new Model.PackageId(dep.Name, version));
                    }
                }
            }

            if (result.Dependencies.Count == 0)
            {
                Console.WriteLine("Found no dependencies for lock file: " + LockFile.Path);
            }

            result.Packages = builder.GetPackageList();
            return(result);
        }