public async Task <UpdateNeeded> IsUpdateNeededAsync(string packageName, bool includePreRelease) { SemanticVersion largestAvailableVersion; try { using (var downloader = new NugetDownloader(commandDirectory)) { var versionFound = await downloader.GetLatestVersionAsync(packageName, includePreRelease); if (versionFound == null) { WriteLineIfVerbose($"Could not find '{packageName}'."); return(UpdateNeeded.PackageNotFound); } largestAvailableVersion = SemanticVersion.Parse(versionFound); } } catch (Exception ex) { WriteLine("Could not download Nuget."); WriteLineIfVerbose(ex.ToString()); return(UpdateNeeded.No); } var directory = commandDirectory.GetDirectoryForPackage(packageName); var packageDirs = Directory.EnumerateDirectories(directory); var packageVersions = packageDirs.Select(packageDir => SemanticVersion.Parse(Path.GetFileName(packageDir))); var largestInstalledVersion = packageVersions.Max(); return(largestInstalledVersion >= largestAvailableVersion ? UpdateNeeded.No : UpdateNeeded.Yes); }
public async Task <bool> InstallAsync(string packageName, SemanticVersion packageVersion, bool force, bool includePreRelease) { WriteLineIfVerbose($"Installing {packageName}..."); PackageInfo packageInfo; try { using (var downloader = new NugetDownloader(commandDirectory)) { packageInfo = await downloader.DownloadAndExtractNugetAsync(packageName, packageVersion, force, includePreRelease); if (packageInfo == null) { return(false); } } } catch (Exception ex) { WriteLineIfVerbose("Could not download Nuget."); WriteLineIfVerbose(ex.ToString()); return(false); } var created = CreateBinFile(packageInfo); if (!created) { if (Directory.Exists(packageInfo.PackageDir)) { WriteLineIfVerbose($"Deleting {packageInfo}..."); Directory.Delete(packageInfo.PackageDir, true); var packageDirectoryForAllVersions = commandDirectory.GetDirectoryForPackage(packageName); if (Directory.EnumerateDirectories(packageDirectoryForAllVersions).Count() <= 1) { Directory.Delete(packageDirectoryForAllVersions, true); } } return(false); } var added = CreateRuntimeConfigDevJsonFile(packageInfo.PackageDir); if (!added) { return(false); } var restored = await RestoreAsync(packageInfo.PackageDir); return(restored); }