public async Task UpdateSolutionAsync(string solutionPath, bool includePreviews = false, bool includeReleaseCandidates = false, bool switchToStable = false, bool checkAll = false) { var projectPaths = ProjectFinder.GetProjectFiles(solutionPath); if (checkAll) { Task.WaitAll(projectPaths.Select(projectPath => UpdateInternalAsync(projectPath, includePreviews, includeReleaseCandidates, switchToStable)).ToArray()); } else { var latestVersionFromNuget = await _nuGetService.GetLatestVersionOrNullAsync("Volo.Abp.Core", includeReleaseCandidates : includeReleaseCandidates); var latestReleaseCandidateVersionFromNuget = await _nuGetService.GetLatestVersionOrNullAsync("Volo.Abp.Core", includeReleaseCandidates : true); var latestVersionFromMyGet = await GetLatestVersionFromMyGet("Volo.Abp.Core"); async Task UpdateAsync(string filePath) { var fileContent = File.ReadAllText(filePath); var updatedContent = await UpdateVoloPackagesAsync(fileContent, includePreviews, includeReleaseCandidates, switchToStable, latestVersionFromNuget, latestReleaseCandidateVersionFromNuget, latestVersionFromMyGet); File.WriteAllText(filePath, updatedContent); } Task.WaitAll(projectPaths.Select(UpdateAsync).ToArray()); } }
public async Task UpdateSolutionAsync(string solutionPath, bool includePreviews = false, bool includeReleaseCandidates = false, bool switchToStable = false, bool checkAll = false, string version = null) { var projectPaths = ProjectFinder.GetProjectFiles(solutionPath); if (checkAll && version.IsNullOrWhiteSpace()) { Task.WaitAll(projectPaths.Select(projectPath => UpdateInternalAsync(projectPath, includePreviews, includeReleaseCandidates, switchToStable)).ToArray()); } else { var latestVersionFromNuget = await _nuGetService.GetLatestVersionOrNullAsync("Volo.Abp.Core", includeReleaseCandidates : includeReleaseCandidates); var latestReleaseCandidateVersionFromNuget = await _nuGetService.GetLatestVersionOrNullAsync("Volo.Abp.Core", includeReleaseCandidates : true); var latestVersionFromMyGet = await GetLatestVersionFromMyGet("Volo.Abp.Core"); async Task UpdateAsync(string filePath) { using (var fs = File.Open(filePath, FileMode.Open, FileAccess.ReadWrite, FileShare.None)) { using (var sr = new StreamReader(fs, Encoding.Default, true)) { var fileContent = await sr.ReadToEndAsync(); var updatedContent = await UpdateVoloPackagesAsync(fileContent, includePreviews, includeReleaseCandidates, switchToStable, latestVersionFromNuget, latestReleaseCandidateVersionFromNuget, latestVersionFromMyGet, version); fs.Seek(0, SeekOrigin.Begin); fs.SetLength(0); using (var sw = new StreamWriter(fs, DefaultEncoding)) { await sw.WriteAsync(updatedContent); await sw.FlushAsync(); } } } } Task.WaitAll(projectPaths.Select(UpdateAsync).ToArray()); } }
private string UpdateVoloPackages(string content, bool includePreviews) { var doc = new XmlDocument() { PreserveWhitespace = true }; doc.LoadXml(content); foreach (XmlNode package in doc.SelectNodes("/Project/ItemGroup/PackageReference[starts-with(@Include, 'Volo.')]")) { var versionAttribute = package.Attributes["Version"]; var packageId = package.Attributes["Include"].Value; var packageVersion = SemanticVersion.Parse(versionAttribute.Value); var latestVersion = AsyncHelper.RunSync(() => _nuGetService.GetLatestVersionOrNullAsync(packageId, includePreviews)); if (latestVersion != null && packageVersion < latestVersion) { versionAttribute.Value = latestVersion.ToString(); } } return(doc.OuterXml); }
private async Task <string> UpdateVoloPackagesAsync(string content, bool includePreviews) { string packageId = null; try { var doc = new XmlDocument() { PreserveWhitespace = true }; doc.LoadXml(content); var packageNodeList = doc.SelectNodes("/Project/ItemGroup/PackageReference[starts-with(@Include, 'Volo.')]"); if (packageNodeList != null) { foreach (XmlNode package in packageNodeList) { if (package.Attributes == null) { continue; } var versionAttribute = package.Attributes["Version"]; packageId = package.Attributes["Include"].Value; var packageVersion = SemanticVersion.Parse(versionAttribute.Value); Logger.LogDebug("Checking package: \"{0}\" - Current version: {1}", packageId, packageVersion); var latestVersion = await _nuGetService.GetLatestVersionOrNullAsync(packageId, includePreviews).ConfigureAwait(false); if (latestVersion != null && packageVersion < latestVersion) { Logger.LogInformation("Updating package \"{0}\" from v{1} to v{2}.", packageId, packageVersion.ToString(), latestVersion.ToString()); versionAttribute.Value = latestVersion.ToString(); } else { Logger.LogDebug("Package: \"{0}-v{1}\" is up to date.", packageId, packageVersion); } } return(await Task.FromResult(doc.OuterXml)); } } catch (Exception ex) { Logger.LogError("Cannot update volo packages! An error occured while updating the package \"{0}\". Error: {1}", packageId, ex.Message); Logger.LogException(ex); } return(await Task.FromResult(content)); }
private async Task <SemanticVersion> GetLatestVersion(UpdateChannel updateChannel) { switch (updateChannel) { case UpdateChannel.Stable: return(await NuGetService.GetLatestVersionOrNullAsync("Volo.Abp.Cli")); case UpdateChannel.Prerelease: return(await NuGetService.GetLatestVersionOrNullAsync("Volo.Abp.Cli", includeReleaseCandidates : true)); case UpdateChannel.Nightly: return(await NuGetService.GetLatestVersionOrNullAsync("Volo.Abp.Cli", includeNightly : true)); default: return(default); } }
private string ReplaceAPackage(string content, bool includePreviews, out int index) { var packageReferenceStartText = "nclude=\"Volo."; var returningText = new StringBuilder(); var indexOfPackageReference = content.IndexOf(packageReferenceStartText, StringComparison.Ordinal); if (indexOfPackageReference < 0) { index = -1; return(content); } returningText.Append(content.Substring(0, indexOfPackageReference + packageReferenceStartText.Length)); content = content.Substring(indexOfPackageReference + packageReferenceStartText.Length); var indexAfterQuote = content.IndexOf("\"", StringComparison.Ordinal) + 1; var packageId = "Volo." + content.Substring(indexAfterQuote - 1); returningText.Append(content.Substring(0, indexAfterQuote)); content = content.Substring(indexAfterQuote); var indexAfterSecondQuote = content.IndexOf("\"", StringComparison.Ordinal) + 1; returningText.Append(content.Substring(0, indexAfterSecondQuote)); content = content.Substring(indexAfterSecondQuote); var indexOfThirdQuote = content.IndexOf("\"", StringComparison.Ordinal); var version = _nuGetService.GetLatestVersionOrNullAsync(packageId, includePreviews); returningText.Append(version); index = indexOfPackageReference + packageReferenceStartText.Length + indexAfterQuote + indexAfterSecondQuote + indexOfThirdQuote; return(returningText.ToString()); }
private async Task <string> GetLatestVersionAsync(string nugetPackage, bool includePreReleases) { var v = await _nuGetService.GetLatestVersionOrNullAsync(nugetPackage, includePreReleases); return(v.ToString()); }