Browse Source

Make update check explicit, see #3101

pull/3111/head
Christoph Wille 2 years ago
parent
commit
6e3b9ecc57
  1. 12
      ICSharpCode.ILSpyCmd/DotNetToolUpdateChecker.cs
  2. 8
      ICSharpCode.ILSpyCmd/IlspyCmdProgram.cs

12
ICSharpCode.ILSpyCmd/DotNetToolUpdateChecker.cs

@ -11,6 +11,8 @@ using NuGet.Versioning; @@ -11,6 +11,8 @@ using NuGet.Versioning;
namespace ICSharpCode.ILSpyCmd
{
internal record PackageCheckResult(NuGetVersion RunningVersion, NuGetVersion LatestVersion, bool UpdateRecommendation);
// Idea from https://github.com/ErikEJ/EFCorePowerTools/blob/master/src/GUI/efcpt/Services/PackageService.cs
internal static class DotNetToolUpdateChecker
{
@ -20,7 +22,7 @@ namespace ICSharpCode.ILSpyCmd @@ -20,7 +22,7 @@ namespace ICSharpCode.ILSpyCmd
.InformationalVersion);
}
public static async Task<NuGetVersion> CheckForPackageUpdateAsync(string packageId)
public static async Task<PackageCheckResult> CheckForPackageUpdateAsync(string packageId)
{
try
{
@ -35,10 +37,10 @@ namespace ICSharpCode.ILSpyCmd @@ -35,10 +37,10 @@ namespace ICSharpCode.ILSpyCmd
CancellationToken.None).ConfigureAwait(false);
var latestVersion = versions.Where(v => v.Release == "").MaxBy(v => v);
if (latestVersion > CurrentPackageVersion())
{
return latestVersion;
}
var runningVersion = CurrentPackageVersion();
int comparisonResult = latestVersion.CompareTo(runningVersion, VersionComparison.Version);
return new PackageCheckResult(runningVersion, latestVersion, comparisonResult > 0);
}
#pragma warning disable RCS1075 // Avoid empty catch clause that catches System.Exception.
catch (Exception)

8
ICSharpCode.ILSpyCmd/IlspyCmdProgram.cs

@ -124,7 +124,7 @@ Examples: @@ -124,7 +124,7 @@ Examples:
private async Task<int> OnExecuteAsync(CommandLineApplication app)
{
Task<NuGetVersion> updateCheckTask = null;
Task<PackageCheckResult> updateCheckTask = null;
if (!DisableUpdateCheck)
{
updateCheckTask = DotNetToolUpdateChecker.CheckForPackageUpdateAsync("ilspycmd");
@ -181,11 +181,11 @@ Examples: @@ -181,11 +181,11 @@ Examples:
if (null != updateCheckTask)
{
var latestVersion = await updateCheckTask;
if (null != latestVersion)
var checkResult = await updateCheckTask;
if (null != checkResult && checkResult.UpdateRecommendation)
{
Console.WriteLine("You are not using the latest version of the tool, please update.");
Console.WriteLine($"Latest version is '{latestVersion}'");
Console.WriteLine($"Latest version is '{checkResult.LatestVersion}' (yours is '{checkResult.RunningVersion}')");
}
}
}

Loading…
Cancel
Save