PowerShell icon indicating copy to clipboard operation
PowerShell copied to clipboard

PSVersionTable should have Release type field denoting Prerelease, Stable, or LTS

Open ThomasNieto opened this issue 1 year ago • 4 comments
trafficstars

Summary of the new feature / enhancement

$PSVersionTable should have a property (Release) field denoting if the version is Prerelease, Stable, or LTS.

Proposed technical implementation details (optional)

$PSVersionTable.Release = if ($PSVersionTable.PSVersion.PreReleaseLabel) {
    'Prerelease'
} elseif ($PSVersionTable.PSVersion.Minor % 2 -eq 0) {
    'LTS'
} else {
    'Stable'
}

ThomasNieto avatar Jun 24 '24 15:06 ThomasNieto

Related:

  • #19121

mklement0 avatar Jun 24 '24 16:06 mklement0

$PSVersionTable.PSVersion.PreReleaseLabel

Why define the release status using PreReleasLabel property when $PSVersionTable.Release returns it?

$ $PSVersionTable.Release
Prerelease

237dmitry avatar Jun 24 '24 16:06 237dmitry

@237dmitry, there is currently no $PSVersionTable.Release entry - except after running the code in the initial post (I don't know how easy it would be to enforce it, but conceptually, $PSVersionTable should be read-only).

@ThomasNieto, I like the idea, but I suggest the following tweaks:

  • To lessen ambiguity and to align with existing key names, I suggest PSReleaseType as the name.
  • Also support detecting custom builds, such as during development (I'm not sure if there's a better way to detect them than what I use below).
  • Use an enum type for the values, for type safety in programmatic use.

Thus, something like the following:

enum PSReleaseType {
  Stable = 0
  LTS
  Prerelease
  Custom
}

$PSVersionTable.PSReleaseType = 
  if ($PSVersionTable.GitCommitId -like '*-*-*') {  # There may be  a better way to detect this
    [PSReleaseType]::Custom
  } elseif ($PSVersionTable.PSVersion.PreReleaseLabel) {
    [PSReleaseType]::Prerelease
  } elseif ($PSVersionTable.PSVersion.Minor % 2 -eq 0) {
    [PSReleaseType]::LTS
  } else {
    [PSReleaseType]::Stable
  }

mklement0 avatar Jun 24 '24 17:06 mklement0

there is currently no $PSVersionTable.Release entry - except after running the code in the initial post (I don't know how easy it would be to enforce it, but conceptually, $PSVersionTable should be read-only).

Yes, I actually ran the original code and then looked at the output of $PSVersionTable

ArcoLinux_2024-06-24_20-55-12

I agree it should be read-only

237dmitry avatar Jun 24 '24 17:06 237dmitry