Skip to content

Instantly share code, notes, and snippets.

@mattleibow
Last active February 23, 2022 19:56
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 mattleibow/2f286fbb61159041b8d38f3540f37ac7 to your computer and use it in GitHub Desktop.
Save mattleibow/2f286fbb61159041b8d38f3540f37ac7 to your computer and use it in GitHub Desktop.
# EXAMPLE USAGE
#
# .\workloads.ps1 `
# -Workloads android,ios,macos,maccatalyst,tvos,maui `
# -RollbackUri https://aka.ms/dotnet/maui/preview.14.json `
# -Sources `
# https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-dotnet-emsdk-ee0a97a0/nuget/v3/index.json,`
# https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-dotnet-runtime-6dd808ff-1/nuget/v3/index.json,`
# https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet6/nuget/v3/index.json
param (
[string] $SdkRoot = 'C:\Program Files\dotnet',
[string] $RollbackUri,
[switch] $SkipInstall,
[string[]] $Workloads,
[string[]] $Sources
)
$ErrorActionPreference = 'Stop'
Add-Type -AssemblyName System.IO.Compression.FileSystem
Write-Host "Downloading rollback file..."
$rollback = Invoke-WebRequest -Uri $RollbackUri | ConvertFrom-Json
Write-Host "Determining SDK bands..."
$sdkBands = Get-ChildItem (Join-Path $SdkRoot "sdk")
| ForEach-Object { ($_.Name | Select-String -Pattern '\d+\.\d+\.\d').Matches[0].Value + "00" }
| Select-Object -Unique
| Sort-Object -Descending
Write-Verbose "Found SDK bands:"
foreach ($band in $sdkBands) {
Write-Verbose " - $band"
}
foreach ($workload in $rollback.PSObject.Properties) {
$name = $workload.Name
$version = $workload.Value
foreach ($band in $sdkBands) {
Write-Verbose "Checking '$name' with version '$version' for SDK band '$band'..."
$destNupkg = Join-Path ([IO.Path]::GetTempPath()) "$name.zip"
$destNupkgExtract = Join-Path ([IO.Path]::GetTempPath()) "$name"
# download
$nugetId = "$name.manifest-$band"
$nupkgUri = "https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet6/nuget/v3/flat2/$nugetId/$version/$nugetId.$version.nupkg"
try {
$oldProgressPreference = $ProgressPreference
$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest -Uri $nupkgUri -OutFile $destNupkg
} catch {
continue
} finally {
$ProgressPreference = $oldProgressPreference
}
Write-Host "Found Manifest ID $name.manifest-$band"
# extract
if (Test-Path $destNupkgExtract) {
Remove-Item -Path $destNupkgExtract -Force -Recurse | Out-Null
}
New-Item -ItemType Directory -Path $destNupkgExtract -Force | Out-Null
[IO.Compression.ZipFile]::ExtractToDirectory($destNupkg, $destNupkgExtract)
# copy
Rename-Item (Join-Path $destNupkgExtract "data") $name
$src = Join-Path $destNupkgExtract $name
$dest = Join-Path $SdkRoot "sdk-manifests" $band
New-Item -ItemType Directory -Path $dest -Force | Out-Null
Copy-Item $src $dest -Recurse -Force
}
}
if (-not $SkipInstall) {
$dotnet = Join-Path $SdkRoot "dotnet"
if (-not $IsMacOS -and -not $IsLinux) {
$dotnet += ".exe"
}
$sourcesFlags = $Sources | ForEach-Object { "--source $_" }
Invoke-Expression "& `"$dotnet`" workload install $Workloads --skip-manifest-update $sourcesFlags"
}
exit $LASTEXITCODE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment