private static NuGetVersion GetNuGetVersion(PackageReference package, NuGetSourceRepositoryProvider sourceRepositoryProvider, NuGetFramework targetFramework, ILogger logger) { if (package.Parameters.ContainsKey("version")) { return(new NuGetVersion(package.Parameters["version"].First())); } var includePrerelease = package.IsPrerelease(); foreach (var sourceRepository in sourceRepositoryProvider.GetRepositories()) { var dependencyInfoResource = sourceRepository.GetResourceAsync <DependencyInfoResource>().Result; var dependencyInfo = dependencyInfoResource.ResolvePackages(package.Package, targetFramework, logger, CancellationToken.None).Result; var version = dependencyInfo .Where(p => p.Listed && (includePrerelease || !p.Version.IsPrerelease)) .OrderByDescending(p => p.Version, VersionComparer.Default) .Select(p => p.Version) .FirstOrDefault(); if (version != null) { return(version); } } return(null); }
public IReadOnlyCollection <IFile> Install(PackageReference package, PackageType type, DirectoryPath path) { if (package == null) { throw new ArgumentNullException(nameof(package)); } if (path == null) { throw new ArgumentNullException(nameof(path)); } var packageRoot = path.MakeAbsolute(_environment).FullPath; var targetFramework = type == PackageType.Addin ? _currentFramework : NuGetFramework.AnyFramework; var sourceRepositoryProvider = new NuGetSourceRepositoryProvider(_nugetSettings, _config, package); var packageIdentity = GetPackageId(package, sourceRepositoryProvider, targetFramework, _nugetLogger); if (packageIdentity == null) { return(Array.Empty <IFile>()); } var pathResolver = new PackagePathResolver(packageRoot); var project = new NugetFolderProject(_fileSystem, _contentResolver, _config, _log, pathResolver, packageRoot, targetFramework); var packageManager = new NuGetPackageManager(sourceRepositoryProvider, _nugetSettings, project.Root) { PackagesFolderNuGetProject = project }; var includePrerelease = package.IsPrerelease(); var dependencyBehavior = GetDependencyBehavior(type, package); var resolutionContext = new ResolutionContext(dependencyBehavior, includePrerelease, false, VersionConstraints.None, _gatherCache); var projectContext = new NuGetProjectContext(_log); using (var sourceCacheContext = new SourceCacheContext()) { var downloadContext = new PackageDownloadContext(sourceCacheContext); // First get the install actions. // This will give us the list of packages to install, and which feed should be used. var actions = packageManager.GetInstallProjectActionsAsync( project, packageIdentity, resolutionContext, projectContext, sourceRepositoryProvider.GetRepositories(), CancellationToken.None).Result; // Then install the packages. packageManager.ExecuteNuGetProjectActionsAsync( project, actions, projectContext, downloadContext, CancellationToken.None).Wait(); } return(project.GetFiles(path, package, type)); }
public IReadOnlyCollection <IFile> Install(PackageReference package, PackageType type, DirectoryPath path) { if (package == null) { throw new ArgumentNullException(nameof(package)); } if (path == null) { throw new ArgumentNullException(nameof(path)); } var packageRoot = path.MakeAbsolute(_environment).FullPath; var targetFramework = type == PackageType.Addin ? _currentFramework : NuGetFramework.AnyFramework; var sourceRepositoryProvider = new NuGetSourceRepositoryProvider(_nugetSettings, _config, package); sourceRepositoryProvider.CreateRepository(packageRoot); var packageIdentity = GetPackageId(package, sourceRepositoryProvider, targetFramework, _nugetLogger); if (packageIdentity == null) { return(Array.Empty <IFile>()); } if (!_projects.TryGetValue(type, out var project)) { var pathResolver = new PackagePathResolver(packageRoot); project = new NugetFolderProject(_fileSystem, _contentResolver, _config, _log, pathResolver, packageRoot, targetFramework); _projects.Add(type, project); if (!project.Root.Equals(packageRoot)) { // This should not happen since all addins/tools are installed to same directory. throw new ArgumentException($"Path is not same as previous package of type: {type}", nameof(path)); } } var packageManager = new NuGetPackageManager(sourceRepositoryProvider, _nugetSettings, project.Root) { PackagesFolderNuGetProject = project }; var sourceRepositories = sourceRepositoryProvider.GetRepositories(); var includePrerelease = false; if (package.Parameters.ContainsKey("prerelease")) { bool.TryParse(package.Parameters["prerelease"].FirstOrDefault() ?? bool.TrueString, out includePrerelease); } var resolutionContext = new ResolutionContext(DependencyBehavior.Lowest, includePrerelease, false, VersionConstraints.None, project.GatherCache); var projectContext = new NuGetProjectContext(_log); packageManager.InstallPackageAsync(project, packageIdentity, resolutionContext, projectContext, sourceRepositories, Array.Empty <SourceRepository>(), CancellationToken.None).Wait(); return(project.GetFiles(path, package, type)); }
public IReadOnlyCollection <IFile> Install(PackageReference package, PackageType type, DirectoryPath path) { if (package == null) { throw new ArgumentNullException(nameof(package)); } if (path == null) { throw new ArgumentNullException(nameof(path)); } var sourceRepositoryProvider = new NuGetSourceRepositoryProvider(_nugetSettings, _config, package); var packageIdentity = GetPackageId(package, sourceRepositoryProvider); if (packageIdentity == null) { return(Array.Empty <IFile>()); } var packageRoot = path.MakeAbsolute(_environment).FullPath; var pathResolver = new PackagePathResolver(packageRoot); var nuGetProject = new NugetFolderProject(_fileSystem, _contentResolver, _config, _log, pathResolver, packageRoot); var packageManager = new NuGetPackageManager(sourceRepositoryProvider, _nugetSettings, packageRoot) { PackagesFolderNuGetProject = nuGetProject }; var sourceRepositories = sourceRepositoryProvider.GetRepositories(); var includePrerelease = false; if (package.Parameters.ContainsKey("prerelease")) { bool.TryParse(package.Parameters["prerelease"].FirstOrDefault() ?? bool.TrueString, out includePrerelease); } var resolutionContext = new ResolutionContext(DependencyBehavior.Lowest, includePrerelease, false, VersionConstraints.None); var projectContext = new NuGetProjectContext(_log); packageManager.InstallPackageAsync(nuGetProject, packageIdentity, resolutionContext, projectContext, sourceRepositories, Array.Empty <SourceRepository>(), CancellationToken.None).Wait(); return(nuGetProject.GetFiles(path, package, type)); }
public IReadOnlyCollection <IFile> Install(PackageReference package, PackageType type, DirectoryPath path) { if (package == null) { throw new ArgumentNullException(nameof(package)); } if (path == null) { throw new ArgumentNullException(nameof(path)); } var packageRoot = path.MakeAbsolute(_environment).FullPath; var targetFramework = type == PackageType.Addin ? _currentFramework : NuGetFramework.AnyFramework; var sourceRepositoryProvider = new NuGetSourceRepositoryProvider(_nugetSettings, _config, package); sourceRepositoryProvider.CreateRepository(packageRoot); var packageIdentity = GetPackageId(package, sourceRepositoryProvider, targetFramework, _nugetLogger); if (packageIdentity == null) { return(Array.Empty <IFile>()); } var pathResolver = new PackagePathResolver(packageRoot); var project = new NugetFolderProject(_fileSystem, _contentResolver, _config, _log, pathResolver, packageRoot, targetFramework); var packageManager = new NuGetPackageManager(sourceRepositoryProvider, _nugetSettings, project.Root) { PackagesFolderNuGetProject = project }; var sourceRepositories = sourceRepositoryProvider.GetRepositories(); var includePrerelease = package.IsPrerelease(); var dependencyBehavior = GetDependencyBehavior(type, package); var resolutionContext = new ResolutionContext(dependencyBehavior, includePrerelease, false, VersionConstraints.None, _gatherCache); var projectContext = new NuGetProjectContext(_log); packageManager.InstallPackageAsync(project, packageIdentity, resolutionContext, projectContext, sourceRepositories, Array.Empty <SourceRepository>(), CancellationToken.None).Wait(); return(project.GetFiles(path, package, type)); }