Skip to content

Commit

Permalink
Add Update-DotnetVersion script
Browse files Browse the repository at this point in the history
Updates donet SDK and Runtime versions together

Allows for
.\Scripts\Update-DotnetVersion.ps1
OR
.\Scripts\Update-DotnetVersion.ps1 7.0
  • Loading branch information
vbjay committed Sep 12, 2022
1 parent 9074ca3 commit 27583c5
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions scripts/Update-DotnetVersion.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
param ( [string]$version = "6.0")

$encoding = [System.Text.UTF8Encoding]::new($false)

$path = Split-Path $MyInvocation.MyCommand.Path -Parent
$uri = "https://raw.githubusercontent.com/dotnet/core/main/release-notes/$version/releases.json"

# Get .NET version info
$releaseJson = Invoke-WebRequest -Uri $uri -ContentType "application/json" -Method Get -UseBasicParsing
$versionResult = $releaseJson.Content | Out-String | ConvertFrom-Json
Write-Output "Dotnet version info"
$versionResult | Format-List -Property channel-version, latest-release, latest-release-date, latest-runtime, latest-sdk, support-phase, eol-date

# Update global.json file
$globalJson = [System.IO.Path]::Combine($path, "..\global.json")
$globalJson = Resolve-Path $globalJson
$json = Get-Content $globalJson | ConvertFrom-Json
Write-Output "Updating SDK version from $($json.sdk.version) to $($versionResult.'latest-sdk')"
$json.sdk.version = $versionResult.'latest-sdk'
$json | ConvertTo-Json | Out-File -Encoding utf8 $globalJson

# Update RepoLayout.props file
$propsPath = [System.IO.Path]::Combine($path, "RepoLayout.props")
[xml]$props = Get-Content -Path $propsPath
$nd = $props.SelectSingleNode("/Project/PropertyGroup/RuntimeFrameworkVersion")
Write-Output "Updating Runtime version from $($nd.'#text') to $($versionResult.'latest-runtime')"
$nd.'#text' = $versionResult.'latest-runtime'
$settings = [System.Xml.XmlWriterSettings]@{
Encoding = $encoding
Indent = $true
}
$writer = [System.Xml.XmlWriter]::Create($propsPath, $settings)
$nd.OwnerDocument.Save($writer)
$writer.Dispose()

0 comments on commit 27583c5

Please sign in to comment.