public List <DllInfo> GetInstallPackagesDllPath(PackageWrapper packageWrapper, ref FolderNuGetProject project) { var dllInfos = new List <DllInfo>(); var packageIdentity = packageWrapper.rootPackageIdentity; var packageFilePath = project.GetInstalledPackageFilePath(packageIdentity); if (!string.IsNullOrWhiteSpace(packageFilePath)) { Logger.LogInformation(packageFilePath); var archiveReader = new PackageArchiveReader(packageFilePath, null, null); var referenceGroup = NugetHelper.Instance.GetMostCompatibleGroup(archiveReader.GetReferenceItems()); if (referenceGroup != null) { foreach (var group in referenceGroup.Items) { var installedPackagedFolder = project.GetInstalledPath(packageIdentity); var installedDllPath = Path.Combine(installedPackagedFolder, group); var installedDllFolder = Path.GetDirectoryName(installedDllPath); var dllName = Path.GetFileName(installedDllPath); var extension = Path.GetExtension(installedDllPath).ToLower(); var processor = group.GetProcessor(); Logger.LogInformation($"dll Path: {installedDllPath}"); //check if file path exist , then only add if (File.Exists(installedDllPath) && extension == ".dll") { dllInfos.Add( new DllInfo() { name = dllName, path = installedDllPath, framework = referenceGroup.TargetFramework.DotNetFrameworkName, processor = processor, rootPackage = packageIdentity.Id } ); } //also , try to cross refer this with expected folder name to avoid version mismatch } } } return(dllInfos); }
public async Task <PackageWrapper> GetPackageByExactSearch(string packageName, IList <NugetRepository> repositories, string version, bool disableCache = false, bool includePrerelease = false, bool includeUnlisted = false) { var sourceRepos = NugetHelper.Instance.GetSourceRepos(repositories); foreach (var sourceRepository in sourceRepos) { IPackageSearchMetadata package; version = version?.Trim(); if (!string.IsNullOrEmpty(version) || !string.Equals("*", version)) { package = await GetPackage(packageName, version, sourceRepository, disableCache); } else { package = await GetLatestPackage(packageName, sourceRepository, includePrerelease, includeUnlisted, disableCache); } if (package == null) { _logger.LogInformation($" No Package found in Repo " + $"{sourceRepository.PackageSource.Source} for package : {packageName} | {version}"); continue; } var packageWrapper = new PackageWrapper { rootPackageIdentity = package.Identity, packageName = package.Identity.Id, version = package.Identity.Version, //save the repo info as well so that during install it doesn't need to search on all repos sourceRepository = sourceRepository, //load child package identities childPackageIdentities = NugetHelper.Instance.GetChildPackageIdentities(package) }; _logger.LogInformation($"Latest Package form Exact Search : {packageWrapper.packageName}" + $"| {packageWrapper.version} in Repo {sourceRepository.PackageSource.Source}"); return(packageWrapper); } return(null); }
public async Task <List <DllInfo> > DownloadPackage(PackageWrapper packageWrapper, string folder, bool disableCache = false, bool includePrelease = true, bool allowUnlisted = false) { _sourceRepos = new List <SourceRepository> { packageWrapper.sourceRepository }; var packageIdentity = packageWrapper.rootPackageIdentity; var providers = new List <Lazy <INuGetResourceProvider> >(); providers.AddRange(Repository.Provider.GetCoreV3()); var rootPath = folder; var settings = Settings.LoadDefaultSettings(rootPath, null, new MachineWideSettings()); var packageSourceProvider = new PackageSourceProvider(settings); var sourceRepositoryProvider = new SourceRepositoryProvider(packageSourceProvider, providers); var project = new NuGet.ProjectManagement.FolderNuGetProject(rootPath); var packageManager = new NuGet.PackageManagement.NuGetPackageManager(sourceRepositoryProvider, settings, rootPath) { PackagesFolderNuGetProject = project }; var projectContext = new ProjectContext(); var resolutionContext = new NuGet.PackageManagement.ResolutionContext( NuGet.Resolver.DependencyBehavior.Lowest, includePrelease, allowUnlisted, NuGet.PackageManagement.VersionConstraints.None); if (disableCache) { resolutionContext.SourceCacheContext.NoCache = true; resolutionContext.SourceCacheContext.DirectDownload = true; } var downloadContext = new PackageDownloadContext(resolutionContext.SourceCacheContext, rootPath, resolutionContext.SourceCacheContext.DirectDownload); var packageAlreadyExists = packageManager.PackageExistsInPackagesFolder(packageIdentity, NuGet.Packaging.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.LogInformation($"Package {packageIdentity.Id} is got Installed at | {project.GetInstalledPath(packageIdentity)} "); } else { _logger.LogInformation($"Package {packageIdentity.Id} is Already Installed at | {project.GetInstalledPath(packageIdentity)} " + $" | skipping installation !!"); } var dlls = NugetHelper.Instance.GetInstallPackagesDllPath(packageWrapper, ref project); _logger.LogInformation($"done for package {packageIdentity.Id} , with total dlls {dlls.Count}"); return(dlls); }