diff --git a/src/PowerShellEditorServices/Services/PowerShell/Context/PowerShellVersionDetails.cs b/src/PowerShellEditorServices/Services/PowerShell/Context/PowerShellVersionDetails.cs
index e84f235b9..ec5b8711f 100644
--- a/src/PowerShellEditorServices/Services/PowerShell/Context/PowerShellVersionDetails.cs
+++ b/src/PowerShellEditorServices/Services/PowerShell/Context/PowerShellVersionDetails.cs
@@ -21,12 +21,6 @@ internal class PowerShellVersionDetails
///
public Version Version { get; }
- ///
- /// Gets the full version string, either the ToString of the Version
- /// property or the GitCommitId for open-source PowerShell releases.
- ///
- public string VersionString { get; }
-
///
/// Gets the PowerShell edition (generally Desktop or Core).
///
@@ -36,15 +30,12 @@ internal class PowerShellVersionDetails
/// Creates an instance of the PowerShellVersionDetails class.
///
/// The version of the PowerShell runtime.
- /// A string representation of the PowerShell version.
/// The string representation of the PowerShell edition.
public PowerShellVersionDetails(
Version version,
- string versionString,
string editionString)
{
Version = version;
- VersionString = versionString;
Edition = editionString;
}
@@ -59,7 +50,6 @@ public PowerShellVersionDetails(
public static PowerShellVersionDetails GetVersionDetails(ILogger logger, PowerShell pwsh)
{
Version powerShellVersion = new(5, 0);
- string versionString = null;
string powerShellEdition = "Desktop";
try
@@ -89,8 +79,6 @@ public static PowerShellVersionDetails GetVersionDetails(ILogger logger, PowerSh
// Expected version string format is 6.0.0-alpha so build a simpler version from that
powerShellVersion = new Version(version.ToString().Split('-')[0]);
}
-
- versionString = psVersionTable["GitCommitId"] is string gitCommitId ? gitCommitId : powerShellVersion.ToString();
}
}
catch (Exception ex)
@@ -99,7 +87,7 @@ public static PowerShellVersionDetails GetVersionDetails(ILogger logger, PowerSh
"Failed to look up PowerShell version, defaulting to version 5.\r\n\r\n" + ex.ToString());
}
- return new PowerShellVersionDetails(powerShellVersion, versionString, powerShellEdition);
+ return new PowerShellVersionDetails(powerShellVersion, powerShellEdition);
}
}
}
diff --git a/src/PowerShellEditorServices/Services/PowerShell/Handlers/GetVersionHandler.cs b/src/PowerShellEditorServices/Services/PowerShell/Handlers/GetVersionHandler.cs
index 2490c8ad8..025f92f5a 100644
--- a/src/PowerShellEditorServices/Services/PowerShell/Handlers/GetVersionHandler.cs
+++ b/src/PowerShellEditorServices/Services/PowerShell/Handlers/GetVersionHandler.cs
@@ -16,7 +16,7 @@ public async Task Handle(GetVersionParams request, Cancellati
{
Version = VersionUtils.PSVersionString,
Edition = VersionUtils.PSEdition,
- DisplayVersion = VersionUtils.PSVersion.ToString(2),
+ Commit = VersionUtils.GitCommitId,
Architecture = VersionUtils.Architecture
};
}
diff --git a/src/PowerShellEditorServices/Services/PowerShell/Handlers/IGetVersionHandler.cs b/src/PowerShellEditorServices/Services/PowerShell/Handlers/IGetVersionHandler.cs
index c2b4977bd..ac82d85af 100644
--- a/src/PowerShellEditorServices/Services/PowerShell/Handlers/IGetVersionHandler.cs
+++ b/src/PowerShellEditorServices/Services/PowerShell/Handlers/IGetVersionHandler.cs
@@ -14,8 +14,8 @@ internal class GetVersionParams : IRequest { }
internal record PowerShellVersion
{
public string Version { get; init; }
- public string DisplayVersion { get; init; }
public string Edition { get; init; }
+ public string Commit { get; init; }
public string Architecture { get; init; }
}
}
diff --git a/src/PowerShellEditorServices/Utility/VersionUtils.cs b/src/PowerShellEditorServices/Utility/VersionUtils.cs
index 287b7277e..f130039ee 100644
--- a/src/PowerShellEditorServices/Utility/VersionUtils.cs
+++ b/src/PowerShellEditorServices/Utility/VersionUtils.cs
@@ -27,6 +27,11 @@ internal static class VersionUtils
///
public static string PSEdition { get; } = PowerShellReflectionUtils.PSEdition;
+ ///
+ /// Gets the GitCommitId of PowerShell being used.
+ ///
+ public static string GitCommitId { get; } = PowerShellReflectionUtils.GitCommitId;
+
///
/// Gets the string of the PSVersion including prerelease tags if it applies.
///
@@ -84,8 +89,12 @@ internal static class PowerShellReflectionUtils
private static readonly PropertyInfo s_psEditionProperty = s_psVersionInfoType
.GetProperty("PSEdition", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
+ // This property is a string, existing only in PowerShell Core.
+ private static readonly FieldInfo s_psGitCommitIdProperty = s_psVersionInfoType
+ .GetField("GitCommitId", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
+
///
- /// Get's the Version of PowerShell being used. Note: this will get rid of the SemVer 2.0 suffix because apparently
+ /// Gets the Version of PowerShell being used. NOTE: this will get rid of the SemVer 2.0 suffix because apparently
/// that property is added as a note property and it is not there when we reflect.
///
public static Version PSVersion { get; } = s_psVersionProperty.GetValue(null) as Version;
@@ -95,12 +104,19 @@ internal static class PowerShellReflectionUtils
///
public static string PSEdition { get; } = s_psEditionProperty.GetValue(null) as string;
+ ///
+ /// Gets the GitCommitId or at most x.y.z from the PSVersion, making Windows PowerShell conform to SemVer.
+ ///
+ public static string GitCommitId { get; } = s_psGitCommitIdProperty != null
+ ? s_psGitCommitIdProperty.GetValue(null).ToString()
+ : PSVersion.ToString(3);
+
///
/// Gets the stringified version of PowerShell including prerelease tags if it applies.
///
public static string PSVersionString { get; } = s_psCurrentVersionProperty != null
? s_psCurrentVersionProperty.GetValue(null).ToString()
- : s_psVersionProperty.GetValue(null).ToString();
+ : PSVersion.ToString(3);
public static string GetOSArchitecture()
{