From b2e162b844e78f7e4574f87879c1dc7e0b1dbb6b Mon Sep 17 00:00:00 2001 From: Gilbert Sanchez Date: Tue, 26 May 2026 15:30:34 -0700 Subject: [PATCH] fix: add PS5.1 SemanticVersion shim so Resolve-ModuleVersionString returns consistent type (#460) Co-Authored-By: Claude Sonnet 4.6 --- .../Private/Initialize-SemanticVersion.ps1 | 20 +++++++++++++++++++ .../Private/Resolve-ModuleVersionString.ps1 | 16 ++++----------- 2 files changed, 24 insertions(+), 12 deletions(-) create mode 100644 Plaster/Private/Initialize-SemanticVersion.ps1 diff --git a/Plaster/Private/Initialize-SemanticVersion.ps1 b/Plaster/Private/Initialize-SemanticVersion.ps1 new file mode 100644 index 0000000..c1777a6 --- /dev/null +++ b/Plaster/Private/Initialize-SemanticVersion.ps1 @@ -0,0 +1,20 @@ +if (-not ([System.Management.Automation.PSTypeName]'System.Management.Automation.SemanticVersion').Type) { + Add-Type -TypeDefinition @' +namespace System.Management.Automation { + public class SemanticVersion { + public int Major { get; private set; } + public int Minor { get; private set; } + public int Patch { get; private set; } + public SemanticVersion(string version) { + var parts = version.Split('.'); + Major = int.Parse(parts[0]); + Minor = parts.Length > 1 ? int.Parse(parts[1]) : 0; + Patch = parts.Length > 2 ? int.Parse(parts[2]) : 0; + } + public override string ToString() { + return Major + "." + Minor + "." + Patch; + } + } +} +'@ +} diff --git a/Plaster/Private/Resolve-ModuleVersionString.ps1 b/Plaster/Private/Resolve-ModuleVersionString.ps1 index f451aad..b195e51 100644 --- a/Plaster/Private/Resolve-ModuleVersionString.ps1 +++ b/Plaster/Private/Resolve-ModuleVersionString.ps1 @@ -36,17 +36,9 @@ function Resolve-ModuleVersionString { $VersionString = "$VersionString.0" } - if ($PSVersionTable.PSEdition -eq "Core") { - $newObjectSplat = @{ - TypeName = "System.Management.Automation.SemanticVersion" - ArgumentList = $VersionString - } - return New-Object @newObjectSplat - } else { - $newObjectSplat = @{ - TypeName = "System.Version" - ArgumentList = $VersionString - } - return New-Object @newObjectSplat + $newObjectSplat = @{ + TypeName = "System.Management.Automation.SemanticVersion" + ArgumentList = $VersionString } + return New-Object @newObjectSplat }