Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 88 additions & 32 deletions tools/UpdateDotnetRuntime.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
[CmdletBinding()]
param (
[Parameter()]
[string]$SDKVersionOverride
[string]$SDKVersionOverride,

[Parameter()]
[switch]$UpdateMSIPackaging
)

<#
Expand Down Expand Up @@ -61,7 +64,7 @@ function Update-PackageVersion {
"$PSScriptRoot/../test/tools/"
)

Get-ChildItem -Path $paths -Recurse -Filter "*.csproj" -Exclude 'PSGalleryModules.csproj','PSGalleryTestModules.csproj' | ForEach-Object {
Get-ChildItem -Path $paths -Recurse -Filter "*.csproj" -Exclude 'PSGalleryModules.csproj', 'PSGalleryTestModules.csproj' | ForEach-Object {
Write-Verbose -Message "Reading - $($_.FullName)" -Verbose
$prj = [xml] (Get-Content $_.FullName -Raw)
$pkgRef = $prj.Project.ItemGroup.PackageReference
Expand All @@ -70,8 +73,7 @@ function Update-PackageVersion {
if ($null -ne $p -and -not $skipModules.Contains($p.Include)) {
if (-not $packages.ContainsKey($p.Include)) {
$packages.Add($p.Include, @([PkgVer]::new($p.Include, $p.Version, $null, $_.FullName)))
}
else {
} else {
$packages[$p.Include] += [PkgVer]::new($p.Include, $p.Version, $null, $_.FullName)
}
}
Expand Down Expand Up @@ -127,49 +129,103 @@ function Update-CsprojFile([string] $path, $values) {
}
}

$dotnetMetadataPath = "$PSScriptRoot/../DotnetRuntimeMetadata.json"
$dotnetMetadataJson = Get-Content $dotnetMetadataPath -Raw | ConvertFrom-Json
function Get-DotnetUpdate {
try {
$dotnetMetadataPath = "$PSScriptRoot/../DotnetRuntimeMetadata.json"
$nextChannel = (Get-Content $dotnetMetadataPath -Raw | ConvertFrom-Json).sdk.nextChannel
$latestSDKversion = [System.Management.Automation.SemanticVersion] (Invoke-RestMethod -Uri "http://aka.ms/dotnet/$nextChannel/Sdk/productVersion.txt" -ErrorAction Stop | ForEach-Object { $_.Trim() })
$currentVersion = [System.Management.Automation.SemanticVersion] (( Get-Content -Path "$PSScriptRoot/../global.json" -Raw | ConvertFrom-Json).sdk.version)

if ($latestSDKversion -gt $currentVersion) {
$shouldUpdate = $true
$newVersion = $latestSDKversion
} else {
$shouldUpdate = $false
$newVersion = $null
}
} catch {
Write-Verbose -Verbose "Error occured: $_.message"
$shouldUpdate = $false
$newVersion = $null
Write-Error "Error while checking .NET SDK update: $($_.message)"
}

# Channel is like: $Channel = "5.0.1xx-preview2"
$Channel = $dotnetMetadataJson.sdk.channel
return @{
ShouldUpdate = $shouldUpdate
NewVersion = $newVersion
Message = $Message
}
}

Import-Module "$PSScriptRoot/../build.psm1" -Force
$dotnetUpdate = Get-DotnetUpdate

Find-Dotnet
if ($dotnetUpdate.ShouldUpdate) {

if(-not (Get-PackageSource -Name 'dotnet5' -ErrorAction SilentlyContinue))
{
$nugetFeed = ([xml](Get-Content .\nuget.config -Raw)).Configuration.packagesources.add | Where-Object { $_.Key -eq 'dotnet5' } | Select-Object -ExpandProperty Value
Register-PackageSource -Name 'dotnet5' -Location $nugetFeed -ProviderName NuGet
Write-Verbose -Message "Register new package source 'dotnet5'" -Verbose
}
$dotnetMetadataPath = "$PSScriptRoot/../DotnetRuntimeMetadata.json"
$dotnetMetadataJson = Get-Content $dotnetMetadataPath -Raw | ConvertFrom-Json

## Install latest version from the channel
# Channel is like: $Channel = "5.0.1xx-preview2"
$Channel = $dotnetMetadataJson.sdk.channel

$sdkVersion = if ($SDKVersionOverride) { $SDKVersionOverride } else { "latest" }
Import-Module "$PSScriptRoot/../build.psm1" -Force

Install-Dotnet -Channel "$Channel" -Version $sdkVersion
Find-Dotnet

Write-Verbose -Message "Installing .NET SDK completed." -Verbose
if (-not (Get-PackageSource -Name 'dotnet5' -ErrorAction SilentlyContinue)) {
$nugetFeed = ([xml](Get-Content .\nuget.config -Raw)).Configuration.packagesources.add | Where-Object { $_.Key -eq 'dotnet5' } | Select-Object -ExpandProperty Value
Register-PackageSource -Name 'dotnet5' -Location $nugetFeed -ProviderName NuGet
Write-Verbose -Message "Register new package source 'dotnet5'" -verbose
}

$isWindowsEnv = [System.Environment]::OSVersion.Platform -eq [System.PlatformID]::Win32NT
## Install latest version from the channel

$dotnetPath = if ($IsWindowsEnv) { "$env:LocalAppData\Microsoft\dotnet" } else { "$env:HOME/.dotnet" }
$sdkVersion = if ($SDKVersionOverride) { $SDKVersionOverride } else { $dotnetUpdate.NewVersion }

$pathSep = [System.IO.Path]::PathSeparator
Install-Dotnet -Channel "$Channel" -Version $sdkVersion

if (-not (($ENV:PATH -split $pathSep) -contains "$dotnetPath")) {
$env:PATH = "$dotnetPath" + $pathSep + "$ENV:PATH"
}
Write-Verbose -Message "Installing .NET SDK completed." -Verbose

$isWindowsEnv = [System.Environment]::OSVersion.Platform -eq [System.PlatformID]::Win32NT
Comment thread
adityapatwardhan marked this conversation as resolved.
Outdated

$latestSdkVersion = (dotnet --list-sdks | Select-Object -Last 1 ).Split() | Select-Object -First 1
$dotnetPath = if ($IsWindowsEnv) { "$env:LocalAppData\Microsoft\dotnet" } else { "$env:HOME/.dotnet" }

Write-Verbose -Message "Installing .NET SDK completed, version - $latestSdkVersion" -Verbose
$pathSep = [System.IO.Path]::PathSeparator

Update-GlobalJson -Version $latestSdkVersion
if (-not (($ENV:PATH -split $pathSep) -contains "$dotnetPath")) {
$env:PATH = "$dotnetPath" + $pathSep + "$ENV:PATH"
}

$latestSdkVersion = (dotnet --list-sdks | Select-Object -Last 1 ).Split() | Select-Object -First 1

Write-Verbose -Message "Installing .NET SDK completed, version - $latestSdkVersion" -Verbose

Write-Verbose -Message "Updating global.json completed." -Verbose
Update-GlobalJson -Version $latestSdkVersion

Update-PackageVersion
Write-Verbose -Message "Updating global.json completed." -Verbose

Write-Verbose -Message "Updating project files completed." -Verbose
Update-PackageVersion

Write-Verbose -Message "Updating project files completed." -Verbose

if ($UpdateMSIPackaging) {
if (-not $isWindowsEnv) {
throw "UpdateMSIPackaging can only be done on Windows"
}

Import-Module "$PSScriptRoot/../build.psm1" -Force
Import-Module "$PSScriptRoot/packaging" -Force
Start-PSBootstrap -Package
Start-PSBuild -Clean -Configuration Release -CrossGen

try {
Start-PSPackage -Type msi -SkipReleaseChecks -InformationVariable wxsData
} catch {
if ($_.Exception.Message -like "Current files to not match *") {
Copy-Item -Path $($wxsData.MessageData.NewFile) -Destination ($wxsData.MessageData.FilesWxsPath)
Comment thread
adityapatwardhan marked this conversation as resolved.
Write-Verbose -Message "Updating files.wxs file completed." -Verbose
} else {
throw $_
}
}
}
}
1 change: 1 addition & 0 deletions tools/packaging/packaging.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -3383,6 +3383,7 @@ function Test-FileWxs
$newXml | Out-File -FilePath $newXmlFileName -Encoding ascii
Write-Log -message "Updated xml saved to $newXmlFileName."
Write-Log -message "If component files were intentionally changed, such as due to moving to a newer .NET Core runtime, update '$FilesWxsPath' with the content from '$newXmlFileName'."
Write-Information -MessageData @{FilesWxsPath = $FilesWxsPath; NewFile = $newXmlFileName} -Tags 'PackagingWxs'
if ($env:TF_BUILD)
{
Write-Host "##vso[artifact.upload containerfolder=wix;artifactname=wix]$newXmlFileName"
Expand Down