Browse Source

refactor nuget package version updater

pull/3721/head^2
Alper Ebicoglu 7 years ago
parent
commit
0e4edc8e27
  1. 27
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/VoloNugetPackagesVersionUpdater.cs

27
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/VoloNugetPackagesVersionUpdater.cs

@ -42,8 +42,9 @@ namespace Volo.Abp.Cli.ProjectModification
protected virtual async Task UpdateInternalAsync(string projectPath, bool includePreviews = false, bool switchToStable = false) protected virtual async Task UpdateInternalAsync(string projectPath, bool includePreviews = false, bool switchToStable = false)
{ {
var fileContent = File.ReadAllText(projectPath); var fileContent = File.ReadAllText(projectPath);
var updatedContent = await UpdateVoloPackagesAsync(fileContent, includePreviews, switchToStable);
File.WriteAllText(projectPath, await UpdateVoloPackagesAsync(fileContent, includePreviews, switchToStable)); File.WriteAllText(projectPath, updatedContent);
} }
private async Task<string> UpdateVoloPackagesAsync(string content, bool includePreviews = false, bool switchToStable = false) private async Task<string> UpdateVoloPackagesAsync(string content, bool includePreviews = false, bool switchToStable = false)
@ -74,16 +75,13 @@ namespace Volo.Abp.Cli.ProjectModification
var versionAttribute = package.Attributes["Version"]; var versionAttribute = package.Attributes["Version"];
var currentVersion = versionAttribute.Value; var currentVersion = versionAttribute.Value;
var packageVersion = SemanticVersion.Parse(currentVersion); var currentSemanticVersion = SemanticVersion.Parse(currentVersion);
Logger.LogDebug("Checking package: \"{0}\" - Current version: {1}", packageId, packageVersion);
Logger.LogDebug("Checking package: \"{0}\" - Current version: {1}", packageId, currentSemanticVersion);
if (includePreviews || (currentVersion.Contains("-preview") && !switchToStable)) if (includePreviews || (currentVersion.Contains("-preview") && !switchToStable))
{ {
var latestVersion = (await _myGetPackageListFinder.GetPackages()).Packages var latestVersion = await GetLatestVersionFromMyGet(packageId);
.FirstOrDefault(p => p.Id == packageId)
?.Versions.LastOrDefault();
if (currentVersion != latestVersion) if (currentVersion != latestVersion)
{ {
@ -99,14 +97,14 @@ namespace Volo.Abp.Cli.ProjectModification
{ {
var latestVersion = await _nuGetService.GetLatestVersionOrNullAsync(packageId); var latestVersion = await _nuGetService.GetLatestVersionOrNullAsync(packageId);
if (latestVersion != null && (currentVersion.Contains("-preview") || packageVersion < latestVersion)) if (latestVersion != null && (currentVersion.Contains("-preview") || currentSemanticVersion < latestVersion))
{ {
Logger.LogInformation("Updating package \"{0}\" from v{1} to v{2}.", packageId, packageVersion.ToString(), latestVersion.ToString()); Logger.LogInformation("Updating package \"{0}\" from v{1} to v{2}.", packageId, currentSemanticVersion.ToString(), latestVersion.ToString());
versionAttribute.Value = latestVersion.ToString(); versionAttribute.Value = latestVersion.ToString();
} }
else else
{ {
Logger.LogInformation("Package: \"{0}-v{1}\" is up to date.", packageId, packageVersion); Logger.LogInformation("Package: \"{0}-v{1}\" is up to date.", packageId, currentSemanticVersion);
} }
} }
} }
@ -116,11 +114,18 @@ namespace Volo.Abp.Cli.ProjectModification
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.LogError("Cannot update volo packages! An error occured while updating the package \"{0}\". Error: {1}", packageId, ex.Message); Logger.LogError("Cannot update Volo.* packages! An error occured while updating the package \"{0}\". Error: {1}", packageId, ex.Message);
Logger.LogException(ex); Logger.LogException(ex);
} }
return await Task.FromResult(content); return await Task.FromResult(content);
} }
private async Task<string> GetLatestVersionFromMyGet(string packageId)
{
var myGetPack = await _myGetPackageListFinder.GetPackages();
return myGetPack.Packages.FirstOrDefault(p => p.Id == packageId)?.Versions.LastOrDefault();
}
} }
} }

Loading…
Cancel
Save