diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/UpdateCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/UpdateCommand.cs index b046c908e3..2a3259b4c9 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/UpdateCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/UpdateCommand.cs @@ -1,14 +1,10 @@ using System; -using System.Collections.Generic; using System.IO; using System.Linq; -using System.Net.Http; using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; -using Newtonsoft.Json; using Volo.Abp.Cli.Args; -using Volo.Abp.Cli.ProjectBuilding.Github; using Volo.Abp.Cli.ProjectModification; using Volo.Abp.DependencyInjection; @@ -35,12 +31,11 @@ namespace Volo.Abp.Cli.Commands if (solution != null) { - var version = await GetLatestAbpVersion(includePreviews); var solutionName = Path.GetFileName(solution).RemovePostFix(".sln"); - _packagesVersionUpdater.UpdateSolution(solution, version); + _packagesVersionUpdater.UpdateSolution(solution, includePreviews); - Logger.LogInformation($"Volo packages are updated to {version} in {solutionName} solution."); + Logger.LogInformation($"Volo packages are updated in {solutionName} solution."); return; } @@ -48,39 +43,17 @@ namespace Volo.Abp.Cli.Commands if (project != null) { - var version = await GetLatestAbpVersion(includePreviews); var projectName = Path.GetFileName(project).RemovePostFix(".csproj"); - _packagesVersionUpdater.UpdateProject(project, version); + _packagesVersionUpdater.UpdateProject(project, includePreviews); - Logger.LogInformation($"Volo packages are updated to {version} in {projectName} project."); + Logger.LogInformation($"Volo packages are updated in {projectName} project."); return; } Logger.LogError("No solution or project found in this directory."); } - protected virtual async Task GetLatestAbpVersion(bool includePreviews) - { - var url = "https://api.github.com/repos/abpframework/abp/releases"; - - using (var client = new HttpClient()) - { - client.Timeout = TimeSpan.FromMinutes(30); - client.DefaultRequestHeaders.UserAgent.ParseAdd("MyAgent/1.0"); - var result = await client.GetStringAsync(url); - - var releases = JsonConvert.DeserializeObject>(result); - - if (!includePreviews) - { - releases.RemoveAll(v => v.IsPrerelease); - } - - return releases.First().Name.RemovePreFix("v"); - } - } - public static class Options { public static class IncludePreviews diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/VoloPackagesVersionUpdater.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/VoloPackagesVersionUpdater.cs index e97a901879..8e0be8f1a1 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/VoloPackagesVersionUpdater.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/VoloPackagesVersionUpdater.cs @@ -1,28 +1,36 @@ using System; using System.IO; using System.Text; +using Volo.Abp.Cli.NuGet; using Volo.Abp.DependencyInjection; namespace Volo.Abp.Cli.ProjectModification { public class VoloPackagesVersionUpdater : ITransientDependency { - public void UpdateSolution(string solutionPath, string newVersion) + private readonly NuGetService _nuGetService; + + public VoloPackagesVersionUpdater(NuGetService nuGetService) + { + _nuGetService = nuGetService; + } + + public void UpdateSolution(string solutionPath, bool includePreviews) { var projectPaths = ProjectFinder.GetProjectFiles(solutionPath); foreach (var filePath in projectPaths) { - UpdateInternal(filePath, newVersion); + UpdateInternal(filePath, includePreviews); } } - public void UpdateProject(string projectPath, string newVersion) + public void UpdateProject(string projectPath, bool includePreviews) { - UpdateInternal(projectPath, newVersion); + UpdateInternal(projectPath, includePreviews); } - protected virtual void UpdateInternal(string projectPath, string newVersion) + protected virtual void UpdateInternal(string projectPath, bool includePreviews) { var fileContent = File.ReadAllText(projectPath); @@ -32,13 +40,13 @@ namespace Volo.Abp.Cli.ProjectModification while (index >= 0) { fileContent = fileContent.Substring(index); - content.Append(ReplaceAPackage(fileContent, newVersion, out index)); + content.Append(ReplaceAPackage(fileContent, includePreviews, out index)); } File.WriteAllText(projectPath, content.ToString()); } - private string ReplaceAPackage(string content, string version, out int index) + private string ReplaceAPackage(string content, bool includePreviews, out int index) { var packageReferenceStartText = "nclude=\"Volo."; var returningText = new StringBuilder(); @@ -56,6 +64,8 @@ namespace Volo.Abp.Cli.ProjectModification var indexAfterQuote = content.IndexOf("\"", StringComparison.Ordinal) + 1; + var packageId = "Volo." + content.Substring(indexAfterQuote - 1); + returningText.Append(content.Substring(0, indexAfterQuote)); content = content.Substring(indexAfterQuote); @@ -66,6 +76,7 @@ namespace Volo.Abp.Cli.ProjectModification var indexOfThirdQuote = content.IndexOf("\"", StringComparison.Ordinal); + var version = _nuGetService.GetLatestVersionOrNullAsync(packageId, includePreviews); returningText.Append(version); index = indexOfPackageReference + packageReferenceStartText.Length + indexAfterQuote + indexAfterSecondQuote + indexOfThirdQuote;