diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/GeneralPage.xaml.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/GeneralPage.xaml.cs
index e2a5b7938c..064eab2f64 100644
--- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/GeneralPage.xaml.cs
+++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/GeneralPage.xaml.cs
@@ -2,6 +2,10 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+using System.Diagnostics;
+using System.Globalization;
+using ManagedCommon;
+using Microsoft.CmdPal.UI.Helpers;
using Microsoft.CmdPal.UI.ViewModels;
using Microsoft.CmdPal.UI.ViewModels.Services;
using Microsoft.Extensions.DependencyInjection;
@@ -30,8 +34,56 @@ public sealed partial class GeneralPage : Page
{
get
{
- var version = Package.Current.Id.Version;
- return $"Version {version.Major}.{version.Minor}.{version.Build}.{version.Revision}";
+ var versionNo = ResourceLoaderInstance.GetString("Settings_GeneralPage_VersionNo");
+ if (!TryGetPackagedVersion(out var version) && !TryGetAssemblyVersion(out version))
+ {
+ version = "?";
+ }
+
+ return string.Format(CultureInfo.CurrentCulture, versionNo, version);
+ }
+ }
+
+ private static bool TryGetPackagedVersion(out string version)
+ {
+ version = string.Empty;
+ try
+ {
+ // Package.Current throws InvalidOperationException if the app is not packaged
+ var v = Package.Current.Id.Version;
+ version = $"{v.Major}.{v.Minor}.{v.Build}.{v.Revision}";
+ return true;
+ }
+ catch (InvalidOperationException)
+ {
+ return false;
+ }
+ catch (Exception ex)
+ {
+ Logger.LogError("Failed to get version from the package", ex);
+ return false;
+ }
+ }
+
+ private static bool TryGetAssemblyVersion(out string version)
+ {
+ version = string.Empty;
+ try
+ {
+ var processPath = Environment.ProcessPath;
+ if (string.IsNullOrEmpty(processPath))
+ {
+ return false;
+ }
+
+ var info = FileVersionInfo.GetVersionInfo(processPath);
+ version = $"{info.FileMajorPart}.{info.FileMinorPart}.{info.FileBuildPart}.{info.FilePrivatePart}";
+ return true;
+ }
+ catch (Exception ex)
+ {
+ Logger.LogError("Failed to get version from the executable", ex);
+ return false;
}
}
}
diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Strings/en-us/Resources.resw b/src/modules/cmdpal/Microsoft.CmdPal.UI/Strings/en-us/Resources.resw
index 5de0447d35..017c0944ef 100644
--- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Strings/en-us/Resources.resw
+++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Strings/en-us/Resources.resw
@@ -724,4 +724,7 @@ Right-click to remove the key combination, thereby deactivating the shortcut.
Manage fallback order
+
+ Version {0}
+
\ No newline at end of file