Skip to content

Instantly share code, notes, and snippets.

@stknohg
Last active April 17, 2021 09:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stknohg/4447171fce0fa6f83e8f91c979ac8948 to your computer and use it in GitHub Desktop.
Save stknohg/4447171fce0fa6f83e8f91c979ac8948 to your computer and use it in GitHub Desktop.
PowerShell Coreの.NET Coreランタイムバージョンまとめ
function Get-NETCoreRuntimeVersion () {
# pwsh.deps.jsonを検索
$depsJsonPath = Join-Path $PSHOME 'pwsh.deps.json'
if (Test-Path $depsJsonPath) {
$depsContent = Get-Content -LiteralPath $depsJsonPath | ConvertFrom-Json -AsHashtable
$targetName = $depsContent.runtimeTarget.name
$pwshTargetName = $depsContent.targets.$targetName.Keys | ? { $_ -like "pwsh*" }
return $depsContent.targets.$targetName.$pwshTargetName.dependencies."Microsoft.NETCore.App"
}
# pwsh.deps.jsonが無い場合は System.Runtime.dll に埋め込まれている情報を使う
# System.Runtime.dll から CoreFx のコミットIDを取得
$asm = [System.Reflection.Assembly]::GetAssembly([Lazy[object,object]])
$versionInfo = $asm.GetCustomAttributes([System.Reflection.AssemblyInformationalVersionAttribute], $true).InformationalVersion
$commitId = (($versionInfo -split ' ')[-1] -split '/')[-1]
if ("" -eq $commitId) {
Write-Error ('Failed to get git commitid.(versionInfo = {0})' -f $versionInfo)
return ""
}
# コミットIDと対になるバージョンを検索
$gitVersionTag = (Invoke-RestMethod -Uri 'https://api.github.com/repos/dotnet/corefx/tags') |
Where-Object { $_.commit.url -like "*$commitId" } |
Select-Object -ExpandProperty Name
if ($null -eq $gitVersionTag) {
Write-Warning ('Failed to get git version.(commitid = {0})' -f $commitId)
return ""
}
# e.g. v2.1.8 -> 2.1.8
return $gitVersionTag.Substring(1)
}

PowerShell Coreの.NET Coreランタイムバージョンまとめ

PowerShell Core ランタイムバージョン
6.0.0 2.0.4
6.0.1 2.0.5
6.0.2 2.0.6
6.0.3 2.0.7
6.0.4 2.0.7
6.0.5 2.0.7
6.1.0 2.1.3
6.1.1 2.1.5
6.1.2 2.1.7
6.1.3 2.1.8
6.2.0 2.1.8
6.2.1 2.1.11
6.2.2 2.1.12
6.2.3 2.1.13
6.2.4 2.1.13
6.2.5 2.1.18
6.2.6 2.1.19
6.2.7 2.1.20

余談

まあ、ぶっちゃけPowerShell Coreに限った話ならランタイムバージョンはGitHubのソース追った方が早い。

$versionTags = (
    'v6.0.0', 'v6.0.1', 'v6.0.2', 'v6.0.3', 'v6.0.4', 'v6.0.5',
    'v6.1.0', 'v6.1.1', 'v6.1.2', 'v6.1.3',
    'v6.2.0'
)
foreach ($tag in $versionTags) {
    $content = Invoke-RestMethod "https://raw.githubusercontent.com/PowerShell/PowerShell/$tag/PowerShell.Common.props"
    $runtimeVersion = [string]$content.Project.PropertyGroup.RuntimeFrameworkVersion
    Write-Output ('{0} : {1}' -f $tag, $runtimeVersion)
}
@stknohg
Copy link
Author

stknohg commented Apr 17, 2021

PowerShell 7以降ではこのスクリプトは使えません。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment