예제 #1
0
        public async ValueTask <IReadOnlyCollection <PackageDependencyInfo> > GetInstalledPackagesDependencyInfoAsync(
            string projectId,
            bool includeUnresolved,
            CancellationToken cancellationToken)
        {
            Assumes.NotNullOrEmpty(projectId);

            cancellationToken.ThrowIfCancellationRequested();

            NuGetPackageManager packageManager = await _sharedState.GetPackageManagerAsync(cancellationToken);

            NuGetProject?project = await SolutionUtility.GetNuGetProjectAsync(
                _sharedState.SolutionManager,
                projectId,
                cancellationToken);

            Assumes.NotNull(project);

            IEnumerable <PackageDependencyInfo>?results = await packageManager.GetInstalledPackagesDependencyInfo(
                project,
                cancellationToken,
                includeUnresolved);

            if (results == null)
            {
                return(Array.Empty <PackageDependencyInfo>());
            }

            return(results.ToArray());
        }
예제 #2
0
        public async Task DownloadPackage(PackageWrapper packageWrapper)
        {
            try
            {
                //this will prevent install to look in all repos
                _sourceRepos = new List <SourceRepository>();
                _sourceRepos.Add(packageWrapper.sourceRepository);

                var packageIdentity = packageWrapper.rootPackageIdentity;
                var providers       = new List <Lazy <INuGetResourceProvider> >();
                providers.AddRange(Repository.Provider.GetCoreV3()); // Add v3 API s

                var rootPath = NugetHelper.Instance.GetNugetSettings()
                               .NugetFolder;

                //var settings = Settings.LoadDefaultSettings(@"C:\Program Files (x86)\NuGet\Config", "Microsoft.VisualStudio.Offline.config", new MachineWideSettings());
                var machineWideSettings      = new MachineWideSettings();
                var settings                 = new Settings(rootPath);
                var packageSourceProvider    = new PackageSourceProvider(settings);
                var sourceRepositoryProvider = new SourceRepositoryProvider(packageSourceProvider, providers);
                var project = new FolderNuGetProject(rootPath);

                var packageManager = new NuGetPackageManager(sourceRepositoryProvider, settings, rootPath)
                {
                    PackagesFolderNuGetProject = project
                };

                var allowPrereleaseVersions         = true;
                var allowUnlisted                   = false;
                INuGetProjectContext projectContext = new ProjectContext();

                var resolutionContext = new ResolutionContext(DependencyBehavior.Lowest, allowPrereleaseVersions, allowUnlisted, VersionConstraints.None);

                if (NugetHelper.Instance.GetNugetSettings()
                    .DisableCache)
                {
                    resolutionContext.SourceCacheContext.NoCache        = true;
                    resolutionContext.SourceCacheContext.DirectDownload = true;
                }

                var downloadContext = new PackageDownloadContext(resolutionContext.SourceCacheContext, rootPath, resolutionContext.SourceCacheContext.DirectDownload);

                var packageAlreadyExists = packageManager.PackageExistsInPackagesFolder(packageIdentity, PackageSaveMode.None);

                if (!packageAlreadyExists)
                {
                    await packageManager.InstallPackageAsync(project, packageIdentity, resolutionContext, projectContext, downloadContext, _sourceRepos, new List <SourceRepository>(), CancellationToken.None);

                    var packageDeps = packageManager.GetInstalledPackagesDependencyInfo(project, CancellationToken.None, true);
                    _logger.LogDebug($"Package {packageIdentity.Id} is got Installed at 【 {project.GetInstalledPath(packageIdentity)}】 ");
                }
                else
                {
                    var packageDeps = packageManager.GetInstalledPackagesDependencyInfo(project, CancellationToken.None, true);
                    _logger.LogDebug($"Package {packageIdentity.Id} is Already Installed at 【 {project.GetInstalledPath(packageIdentity)} 】" + " | skipping instalation !!");
                }

                #region GetDll paths

                var dllstoAdd = NugetHelper.Instance.GetInstallPackagesDllPath(packageWrapper, ref project);

                if (dllstoAdd.Count > 0)
                {
                    downloadedDllPaths.AddRange(dllstoAdd);
                }

                #endregion

                _logger.LogDebug($"done for package {packageIdentity.Id} , with total Dlls {downloadedDllPaths.Count}");
            }
            catch (Exception e)
            {
                NugetHelper.Instance.logger.LogDebug(e.Message);

                throw;
            }
        }