internal void InstallPackages() { DirectoryPath packagesPath = GetAbsolutePackagesPath(); Trace.Information($"Installing packages to {packagesPath.FullPath} (using {(UseLocalPackagesFolder ? "local" : "global")} packages folder)"); try { // Add the global default sources if requested if (UseGlobalPackageSources) { _sourceRepositories.AddGlobalDefaults(); } // Get the local repository SourceRepository localRepository = _sourceRepositories.CreateRepository(packagesPath.FullPath); // Get the package manager and repositories WyamFolderNuGetProject nuGetProject = new WyamFolderNuGetProject(_fileSystem, _assemblyLoader, _currentFramework, packagesPath.FullPath); NuGetPackageManager packageManager = new NuGetPackageManager(_sourceRepositories, _settings, packagesPath.FullPath) { PackagesFolderNuGetProject = nuGetProject }; IReadOnlyList <SourceRepository> remoteRepositories = _sourceRepositories.GetDefaultRepositories(); // Resolve all the versions IReadOnlyList <SourceRepository> installationRepositories = remoteRepositories; try { ResolveVersions(localRepository, remoteRepositories); } catch (Exception ex) { Trace.Verbose($"Exception while resolving package versions: {ex.Message}"); Trace.Warning("Error while resolving package versions, attempting without remote repositories"); installationRepositories = new[] { localRepository }; ResolveVersions(localRepository, Array.Empty <SourceRepository>()); } // Install the packages (doing this synchronously since doing it in parallel triggers file lock errors in NuGet on a clean system) try { InstallPackages(packageManager, installationRepositories); } catch (Exception ex) { Trace.Verbose($"Exception while installing packages: {(ex is AggregateException ? string.Join("; ", ((AggregateException)ex).InnerExceptions.Select(x => x.Message)) : ex.Message)}"); Trace.Warning("Error while installing packages, attempting without remote repositories"); InstallPackages(packageManager, new[] { localRepository }); } // Process the package (do this after all packages have been installed) nuGetProject.ProcessAssembliesAndContent(); } catch (Exception ex) { Trace.Verbose($"Unexpected exception while installing packages: {(ex is AggregateException ? string.Join("; ", ((AggregateException)ex).InnerExceptions.Select(x => x.Message)) : ex.Message)}"); Trace.Warning("Error while installing packages, attempting to continue anyway"); } }
// Based primarily on NuGet.CommandLine.Commands.UpdateCommand internal void InstallPackages() { Trace.Verbose($"Installing packages to {GetAbsolutePackagesPath().FullPath} (using {(UseLocal ? "local" : "global")} packages folder)"); SourceRepository localSourceRepository = SourceRepositoryProvider.CreateRepository(new PackageSource(GetAbsolutePackagesPath().FullPath)); List <SourceRepository> defaultSourceRepositories = _packageSources.Select(SourceRepositoryProvider.CreateRepository).ToList(); // Install the packages _nuGetProject.StartPackageInstall(); Parallel.ForEach(_packages, package => { List <SourceRepository> sourceRepositories = defaultSourceRepositories; if (package.PackageSources != null && package.PackageSources.Count > 0) { sourceRepositories = package.PackageSources.Select(SourceRepositoryProvider.CreateRepository).ToList(); if (!package.Exclusive) { sourceRepositories = sourceRepositories.Concat(defaultSourceRepositories).ToList(); } } package.InstallPackage(this, UpdatePackages, localSourceRepository, sourceRepositories); }); // Process the package (do this after all packages have been installed) _nuGetProject.ProcessAssembliesAndContent(); }