public WyamFolderNuGetProject(IFileSystem fileSystem, AssemblyLoader assemblyLoader, NuGetFramework currentFramework, InstalledPackagesCache installedPackages, string root) : base(root) { _fileSystem = fileSystem; _assemblyLoader = assemblyLoader; _currentFramework = currentFramework; _installedPackages = installedPackages; }
public async Task Install( IReadOnlyList <SourceRepository> remoteRepositories, InstalledPackagesCache installedPackages, NuGetPackageManager packageManager, ISettings settings) { if (_versionMatch == null) { return; } IReadOnlyList <SourceRepository> sourceRepositories = GetSourceRepositories(remoteRepositories); using (Trace.WithIndent().Verbose($"Installing package {_packageId} {_versionMatch.ToNormalizedString()}")) { // Check if this package was already installed in a previous run PackageIdentity packageIdentity = new PackageIdentity(_packageId, _versionMatch); if (installedPackages.VerifyPackage(packageIdentity, packageManager)) { Trace.Verbose($"Package {_packageId} {_versionMatch.ToNormalizedString()} was already installed"); return; } // If not, go ahead and install it using (installedPackages.AddPackage(packageIdentity, _currentFramework)) { ResolutionContext resolutionContext = new ResolutionContext( DependencyBehavior.Lowest, _allowPrereleaseVersions, _allowUnlisted, VersionConstraints.None); ILogger logger = new NuGetLogger(); ClientPolicyContext clientPolicyContext = ClientPolicyContext.GetClientPolicy(settings, logger); INuGetProjectContext projectContext = new NuGetProjectContext { PackageExtractionContext = new global::NuGet.Packaging.PackageExtractionContext( global::NuGet.Packaging.PackageSaveMode.Defaultv3, global::NuGet.Packaging.XmlDocFileSaveMode.None, clientPolicyContext, logger) }; await packageManager.InstallPackageAsync( packageManager.PackagesFolderNuGetProject, packageIdentity, resolutionContext, projectContext, sourceRepositories, Array.Empty <SourceRepository>(), CancellationToken.None); Trace.Verbose($"Installed package {_packageId} {_versionMatch.ToNormalizedString()}"); } } }
private void InstallPackages(NuGetPackageManager packageManager, IReadOnlyList <SourceRepository> installationRepositories, InstalledPackagesCache installedPackages) { foreach (Package package in _packages.Values) { package.Install(installationRepositories, installedPackages, packageManager).GetAwaiter().GetResult(); } }
internal void InstallPackages(FilePath configFilePath) { 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(); } // Add the default package sources if (!IgnoreDefaultSources) { _sourceRepositories.AddDefaultPackageSources(); } // Get the local repository SourceRepository localRepository = _sourceRepositories.CreateRepository(packagesPath.FullPath); // Cache the packages in a packages file FilePath packagesFilePath = configFilePath?.AppendExtension(".packages.xml"); if (packagesFilePath == null) { Trace.Verbose("Will not write packages file since no config file was provided"); } else { Trace.Verbose($"Writing packages file to {packagesFilePath.FullPath}"); } using (InstalledPackagesCache installedPackages = new InstalledPackagesCache(packagesFilePath, UpdatePackages)) { // Get the package manager and repositories WyamFolderNuGetProject nuGetProject = new WyamFolderNuGetProject(_fileSystem, _assemblyLoader, _currentFramework, installedPackages, 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, installedPackages); } catch (Exception ex) { Trace.Verbose($"Exception while installing packages: {(ex is AggregateException aex ? aex.Flatten() : ex)}"); Trace.Warning("Error while installing packages, attempting without remote repositories"); InstallPackages(packageManager, Array.Empty <SourceRepository>(), installedPackages); } // 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"); } }