public IQueryable <IPackage> GetPackages()
        {
            CancellationTokenSource cts = new CancellationTokenSource();
            var task = _project.GetInstalledPackagesAsync(cts.Token);

            task.Wait();

            List <IPackage> packages = new List <IPackage>();

            foreach (object item in task.Result)
            {
                var moniker = item as INuGetPackageMoniker;
                if (moniker != null)
                {
                    packages.Add(new DataServicePackage()
                    {
                        Id      = moniker.Id,
                        Version = moniker.Version
                    });

                    continue;
                }

                var fileName = item as string;
                if (item != null)
                {
                    packages.Add(new OptimizedZipPackage(fileName));
                }
            }
            return(packages.AsQueryable());
        }
        public override async Task <IEnumerable <Packaging.PackageReference> > GetInstalledPackagesAsync(CancellationToken token)
        {
            var result = new List <Packaging.PackageReference>();

            foreach (object item in await _project.GetInstalledPackagesAsync(token))
            {
                PackageIdentity identity = null;

                var moniker = item as INuGetPackageMoniker;
                if (moniker != null)
                {
                    identity = new PackageIdentity(
                        moniker.Id,
                        NuGetVersion.Parse(moniker.Version));
                }
                else
                {
                    // otherwise, item is the file name of the nupkg file
                    var fileName = item as string;
                    using (var packageReader = new PackageArchiveReader(fileName))
                    {
                        identity = packageReader.GetIdentity();
                    }
                }

                result.Add(new Packaging.PackageReference(
                               identity,
                               targetFramework: null));
            }

            return(result);
        }
Пример #3
0
        public override async Task <IEnumerable <PackageReference> > GetInstalledPackagesAsync(CancellationToken token)
        {
            var result = new List <PackageReference>();

            foreach (object item in await _project.GetInstalledPackagesAsync(token))
            {
                PackageIdentity identity = null;

                var moniker = item as INuGetPackageMoniker;
                if (moniker != null)
                {
                    // As with build integrated projects (UWP project.json), treat the version as a
                    // version range and use the minimum version of that range. Eventually, this
                    // method should return VersionRange instances, not NuGetVersion so that the
                    // UI can express the full project.json intent. This improvement is tracked
                    // here: https://github.com/NuGet/Home/issues/3101
                    var versionRange = VersionRange.Parse(moniker.Version);
                    var version      = versionRange.MinVersion;

                    identity = new PackageIdentity(moniker.Id, version);
                }
                else
                {
                    // otherwise, item is the file name of the nupkg file
                    var fileName = item as string;
                    using (var packageReader = new PackageArchiveReader(fileName))
                    {
                        identity = packageReader.GetIdentity();
                    }
                }

                result.Add(new PackageReference(
                               identity,
                               targetFramework: null));
            }

            return(result);
        }
 public Task <IReadOnlyCollection <object> > GetInstalledPackagesAsync(CancellationToken cancellationToken)
 {
     return(_nugetProject.GetInstalledPackagesAsync(cancellationToken));
 }