Beispiel #1
0
        public override Task InstallPackage(
            PackageIdentity id,
            IEnumerable <FrameworkName> packageSupportedFrameworks,
            IExecutionLogger logger,
            CancellationToken cancelToken)
        {
            var args = new Dictionary <string, object>();
            var projectFrameworks = _nugetAwareProject.GetSupportedFrameworksAsync(cancelToken).Result;

            args["Frameworks"] = projectFrameworks.Where(
                projectFramework =>
                NuGet.VersionUtility.IsCompatible(
                    projectFramework,
                    packageSupportedFrameworks)).ToArray();
            var task = _nugetAwareProject.InstallPackageAsync(
                new NuGetPackageMoniker
            {
                Id      = id.Id,
                Version = id.Version.ToString()
            },
                args,
                logger: null,
                progress: null,
                cancellationToken: cancelToken);

            return(task);
        }
        public ProjectKNuGetProject(INuGetPackageManager project, string projectName, string uniqueName)
        {
            _project = project;
            InternalMetadata.Add(NuGetProjectMetadataKeys.Name, projectName);
            InternalMetadata.Add(NuGetProjectMetadataKeys.UniqueName, uniqueName);

            var supportedFrameworks = _project.GetSupportedFrameworksAsync(CancellationToken.None)
                .Result
                .Select(f => NuGetFramework.Parse(f.FullName));

            InternalMetadata.Add(NuGetProjectMetadataKeys.SupportedFrameworks, supportedFrameworks);
        }
        public ProjectKNuGetProject(INuGetPackageManager project, string projectName, string uniqueName)
        {
            _project = project;
            InternalMetadata.Add(NuGetProjectMetadataKeys.Name, projectName);
            InternalMetadata.Add(NuGetProjectMetadataKeys.UniqueName, uniqueName);

            var supportedFrameworks = _project.GetSupportedFrameworksAsync(CancellationToken.None)
                                      .Result
                                      .Select(f => NuGetFramework.Parse(f.FullName));

            InternalMetadata.Add(NuGetProjectMetadataKeys.SupportedFrameworks, supportedFrameworks);
        }
        public override IEnumerable <FrameworkName> GetSupportedFrameworks()
        {
#if VS14
            if (_nugetAwareProject != null)
            {
                using (var cts = new CancellationTokenSource())
                {
                    var task = _nugetAwareProject.GetSupportedFrameworksAsync(cts.Token);
                    return(task.Result);
                }
            }
#endif

            return(new FrameworkName[] { DteProject.GetTargetFrameworkName() });
        }
        public ProjectKNuGetProject(INuGetPackageManager project, string projectName, string uniqueName, string projectId)
        {
            _project = project;
            InternalMetadata.Add(NuGetProjectMetadataKeys.Name, projectName);
            InternalMetadata.Add(NuGetProjectMetadataKeys.UniqueName, uniqueName);
            InternalMetadata.Add(NuGetProjectMetadataKeys.ProjectId, projectId);

            NuGetUIThreadHelper.JoinableTaskFactory.Run(async() =>
            {
                var frameworks          = await _project.GetSupportedFrameworksAsync(CancellationToken.None);
                var supportedFrameworks = frameworks.Select(f => NuGetFramework.Parse(f.FullName));

                InternalMetadata.Add(NuGetProjectMetadataKeys.SupportedFrameworks, supportedFrameworks);
            });
        }
Beispiel #6
0
        private void AddPackageReferenceToNuGetAwareProject(IPackage package)
        {
            INuGetPackageManager        project = this.Project as INuGetPackageManager;
            Dictionary <string, object> options = new Dictionary <string, object>();

            using (CancellationTokenSource source = new CancellationTokenSource())
            {
                IEnumerable <FrameworkName>         packageSupportedFrameworks = package.GetSupportedFrameworks();
                IReadOnlyCollection <FrameworkName> result = project.GetSupportedFrameworksAsync(source.Token).Result;
                options["Frameworks"] = (from projectFramework in result
                                         where VersionUtility.IsCompatible(projectFramework, packageSupportedFrameworks)
                                         select projectFramework).ToArray <FrameworkName>();
                NuGetPackageMoniker moniker1 = new NuGetPackageMoniker();
                moniker1.Id      = package.Id;
                moniker1.Version = package.Version.ToString();
                project.InstallPackageAsync(moniker1, options, null, null, source.Token).Wait();
            }
        }
        public override async Task <bool> InstallPackageAsync(
            PackageIdentity packageIdentity,
            DownloadResourceResult downloadResourceResult,
            INuGetProjectContext nuGetProjectContext,
            CancellationToken token)
        {
            if (downloadResourceResult == null)
            {
                throw new ArgumentNullException(nameof(downloadResourceResult));
            }

            var packageStream = downloadResourceResult.PackageStream;

            if (!packageStream.CanSeek)
            {
                throw new ArgumentException(ProjectManagement.Strings.PackageStreamShouldBeSeekable);
            }

            nuGetProjectContext.Log(ProjectManagement.MessageLevel.Info, Strings.InstallingPackage, packageIdentity);

            packageStream.Seek(0, SeekOrigin.Begin);
            var packageSupportedFrameworks = GetSupportedFrameworks(packageStream);
            var projectFrameworks          = _project.GetSupportedFrameworksAsync(token)
                                             .Result
                                             .Select(f => NuGetFramework.Parse(f.FullName));

            var args = new Dictionary <string, object>();

            args["Frameworks"] = projectFrameworks.Where(
                projectFramework =>
                IsCompatible(projectFramework, packageSupportedFrameworks)).ToArray();
            await _project.InstallPackageAsync(
                new NuGetPackageMoniker
            {
                Id      = packageIdentity.Id,
                Version = packageIdentity.Version.ToNormalizedString()
            },
                args,
                logger : null,
                progress : null,
                cancellationToken : token);

            return(true);
        }
Beispiel #8
0
        public async override Task <bool> InstallPackageAsync(Packaging.Core.PackageIdentity packageIdentity, System.IO.Stream packageStream,
                                                              INuGetProjectContext nuGetProjectContext, CancellationToken token)
        {
            if (!packageStream.CanSeek)
            {
                throw new ArgumentException(NuGet.ProjectManagement.Strings.PackageStreamShouldBeSeekable);
            }

            nuGetProjectContext.Log(MessageLevel.Info, Strings.InstallingPackage, packageIdentity);

            packageStream.Seek(0, SeekOrigin.Begin);
            var           zipArchive    = new ZipArchive(packageStream);
            PackageReader packageReader = new PackageReader(zipArchive);
            var           packageSupportedFrameworks = packageReader.GetSupportedFrameworks();
            var           projectFrameworks          = _project.GetSupportedFrameworksAsync(token)
                                                       .Result
                                                       .Select(f => NuGetFramework.Parse(f.FullName));

            var args = new Dictionary <string, object>();

            args["Frameworks"] = projectFrameworks.Where(
                projectFramework =>
                IsCompatible(projectFramework, packageSupportedFrameworks)).ToArray();
            await _project.InstallPackageAsync(
                new NuGetPackageMoniker
            {
                Id      = packageIdentity.Id,
                Version = packageIdentity.Version.ToNormalizedString()
            },
                args,
                logger : null,
                progress : null,
                cancellationToken : token);

            return(true);
        }
 public Task <IReadOnlyCollection <FrameworkName> > GetSupportedFrameworksAsync(CancellationToken cancellationToken)
 {
     return(_nugetProject.GetSupportedFrameworksAsync(cancellationToken));
 }