diff --git a/ICSharpCode.ILSpyCmd/DotNetToolUpdateChecker.cs b/ICSharpCode.ILSpyCmd/DotNetToolUpdateChecker.cs index 449cceb82..79b3d921c 100644 --- a/ICSharpCode.ILSpyCmd/DotNetToolUpdateChecker.cs +++ b/ICSharpCode.ILSpyCmd/DotNetToolUpdateChecker.cs @@ -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 .InformationalVersion); } - public static async Task CheckForPackageUpdateAsync(string packageId) + public static async Task CheckForPackageUpdateAsync(string packageId) { try { @@ -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) diff --git a/ICSharpCode.ILSpyCmd/IlspyCmdProgram.cs b/ICSharpCode.ILSpyCmd/IlspyCmdProgram.cs index 8413fdfc4..425357cac 100644 --- a/ICSharpCode.ILSpyCmd/IlspyCmdProgram.cs +++ b/ICSharpCode.ILSpyCmd/IlspyCmdProgram.cs @@ -124,7 +124,7 @@ Examples: private async Task OnExecuteAsync(CommandLineApplication app) { - Task updateCheckTask = null; + Task updateCheckTask = null; if (!DisableUpdateCheck) { updateCheckTask = DotNetToolUpdateChecker.CheckForPackageUpdateAsync("ilspycmd"); @@ -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}')"); } } }