public List <Tuple <NuGetPackage, V2FeedPackage> > RetrieveInformationFromNuGet(List <NuGetPackage> packages)
        {
            List <Tuple <NuGetPackage, V2FeedPackage> > result = new List <Tuple <NuGetPackage, V2FeedPackage> >();

            var context = new V2FeedContext(new Uri("https://www.nuget.org/api/v2"));

            foreach (var package in packages)
            {
                var packageExistsInRemoteLocation =
                    context.Packages.Where(x => x.Id == package.Id).OrderByDescending(x => x.Version).Take(1).ToList().Any();

                V2FeedPackage v2FeedPackage = null;

                if (packageExistsInRemoteLocation)
                {
                    var nugetPackageInformations =
                        context.Packages.Where(x => (x.Id == package.Id) && (x.Version == package.Version)).ToList();

                    v2FeedPackage = nugetPackageInformations.SingleOrDefault();
                }

                result.Add(new Tuple <NuGetPackage, V2FeedPackage>(package, v2FeedPackage));
            }

            return(result);
        }
Пример #2
0
        public static void InstallPackage(this IVsPackageInstaller packageInstaller, Project project, string packageName, IVsPackageInstallerServices packageInstallerServices, string version = null)
        {
            if (version == null)
            {
                version = new V2FeedContext(new Uri("http://www.nuget.org/api/v2/")).Execute <V2FeedPackage>(new Uri("http://www.nuget.org/api/v2/Packages?$filter=IsAbsoluteLatestVersion and Id eq '" + packageName + "'&$skip=0&$top=1&$select=Id,Version&targetFramework=&includePrerelease=true")).Single().Version;
            }
            packageInstaller.InstallPackage("http://packages.nuget.org", project, packageName, version, false);
            //workaround to the bug on Package installer that does not install package depencences
            var dependencies = new LocalPackageRepository(packageInstallerServices.GetPackageLocation(packageName)).FindPackage(packageName).DependencySets.SelectMany(ds => ds.Dependencies);

            foreach (var dependency in dependencies)
            {
                InstallPackage(packageInstaller, project, dependency.Id, packageInstallerServices, dependency.VersionSpec.ToString());
            }
        }
Пример #3
0
        private async Task FillDataFromNuGetGallery(FeatureTable table, ILibrary library, Feature released, Feature downloads)
        {
            if (library.PackageId == null)   // this is always intentional
            {
                FillWithNA(table[library, released]);
                FillWithNA(table[library, downloads]);
                return;
            }

            var localPackage         = this.packageCache.GetPackage(library.PackageId);
            var localVersion         = localPackage.Version.ToString();
            var versionMatchingLocal = await Task.Run(() => {
                var context = new V2FeedContext(new Uri("http://nuget.org/api/v2"));
                return(context.Packages.Where(p => p.Id == library.PackageId && p.Version == localVersion).AsEnumerable().Single());
            });

            table[library, released].DisplayValue  = new DateTimeOffset(versionMatchingLocal.Published);
            table[library, downloads].DisplayValue = versionMatchingLocal.DownloadCount;
        }