public async Task <IEnumerable <Package> > GetInstalledPackages() { _choco.Set( config => { config.CommandName = CommandNameType.list.ToString(); config.ListCommand.LocalOnly = true; }); var chocoConfig = _choco.GetConfiguration(); // Not entirely sure what is going on here. When there are no sources defined, for example, when they // are all disabled, the ListAsync command isn't returning any packages installed locally. When in this // situation, use the nugetService directly to get the list of installed packages. if (chocoConfig.Sources != null) { var packages = await _choco.ListAsync <PackageResult>(); return(packages .Select(package => GetMappedPackage(_choco, package, _mapper, true)) .ToArray()); } else { var nugetService = _choco.Container().GetInstance <INugetService>(); var packages = await Task.Run(() => nugetService.list_run(chocoConfig)); return(packages .Select(package => GetMappedPackage(_choco, package, _mapper, true)) .ToArray()); } }
// This can take a while with many packages private static int GetOutdatedCount() { GetChocolatey chocolatey = Lets.GetChocolatey(); chocolatey.SetCustomLogging(new chocolatey.infrastructure.logging.NullLog()); chocolatey.Set(c => { c.CommandName = "outdated"; c.PackageNames = ApplicationParameters.AllPackages; }); INugetService nuget = chocolatey.Container().GetInstance <INugetService>(); ConcurrentDictionary <string, PackageResult> upgradeResults = nuget.upgrade_noop(chocolatey.GetConfiguration(), null); return(upgradeResults.Values.Count((v) => { return !v.Inconclusive; })); }