Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add script for installing Windows SDK from ISO #2220

Merged
merged 4 commits into from
Jul 11, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions .vsts-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ steps:
inputs:
versionSpec: 4.6.2

- powershell: .\build\Install-WindowsSdkISO.ps1 17704
displayName: Insider SDK

- task: DotNetCoreCLI@2
inputs:
command: build
Expand Down
3 changes: 3 additions & 0 deletions .vsts-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ steps:
inputs:
versionSpec: 4.6.2

- powershell: .\build\Install-WindowsSdkISO.ps1 17704
displayName: Insider SDK

- powershell: .\build\build.ps1 -target=Package
displayName: Build

Expand Down
121 changes: 121 additions & 0 deletions build/Install-WindowsSdkISO.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# Set the URI for the SDK
param([string]$buildNumber)

$uri = "https://go.microsoft.com/fwlink/?prd=11966&pver=1.0&plcid=0x409&clcid=0x409&ar=Flight&sar=Sdsurl&o1=$buildNumber"

if ($env:TEMP -eq $null) {
$env:TEMP = Join-Path $env:SystemDrive 'temp'
}

$winsdkTempDir = Join-Path $env:TEMP "WindowsSDK"

if (![System.IO.Directory]::Exists($winsdkTempDir)) {
[void][System.IO.Directory]::CreateDirectory($winsdkTempDir)
}

$file = "winsdk.iso"

function Download-File {
param (
[string] $outDir,
[string] $downloadUrl,
[string] $downloadName
)
# The ISO file can be large (800 MB), we want to use smart caching if we can to avoid long delays
# Note that some sources explicitly disable caching, so this may not be possible
$etagFile = Join-path $outDir "$downloadName.ETag"
$downloadPath = Join-Path $outDir "$downloadName.download"
$downloadDest = Join-Path $outDir $downloadName
$downloadDestTemp = Join-Path $outDir "$downloadName.tmp"
$headers = @{}

Write-Host -NoNewline "Ensuring that $downloadName is up to date..."

# if the destination folder doesn't exist, delete the ETAG file if it exists
if (!(Test-Path -PathType Container $downloadDest) -and (Test-Path -PathType Container $etagFile)) {
Remove-Item -Force $etagFile
}

if (Test-Path $etagFile) {
$headers.Add("If-None-Match", [System.IO.File]::ReadAllText($etagFile))
}

try {
# Dramatically speeds up download performance
$ProgressPreference = 'SilentlyContinue'
$response = Invoke-WebRequest -Headers $headers -Uri $downloadUrl -PassThru -OutFile $downloadPath -UseBasicParsing
} catch [System.Net.WebException] {
$response = $_.Exception.Response
}

if ($response.StatusCode -eq 200) {
Unblock-File $downloadPath
[System.IO.File]::WriteAllText($etagFile, $response.Headers["ETag"])

$downloadDestTemp = $downloadPath;


# Delete and rename to final dest
if (Test-Path -PathType Container $downloadDest) {
[System.IO.Directory]::Delete($downloadDest, $true)
}

Move-Item -Force $downloadDestTemp $downloadDest
Write-Host "Updated $downloadName"
} elseif ($response.StatusCode -eq 304) {
Write-Host "Done"
} else {
Write-Host
Write-Warning "Failed to fetch updated file from $downloadUrl"
if (!(Test-Path $downloadDest)) {
throw "$downloadName was not found at $downloadDest"
} else {
Write-Warning "$downloadName may be out of date"
}
}

return $downloadDest
}

function Mount-ISO {
param (
[string] $isoPath
)
# Check if image is already mounted
$isoDrive = (Get-DiskImage -ImagePath $isoPath | Get-Volume).DriveLetter

if (!$isoDrive) {
Mount-DiskImage -ImagePath $isoPath -StorageType ISO
}

$isoVolume = (Get-DiskImage -ImagePath $isoPath | Get-Volume)
$isoDrive = $isoVolume.DriveLetter + ":"

Write-Host "$isoPath mounted to $isoDrive"

return $isoDrive
}

function Dismount-ISO {
param (
[string] $isoPath
)
$isoDrive = (Get-DiskImage -ImagePath $isoPath | Get-Volume).DriveLetter
if ($isoDrive) {
Dismount-DiskImage -ImagePath $isoPath
}
}

Write-Output "Getting WinSDK from $uri"
$downloadFile = Download-File $winsdkTempDir $uri $file

# TODO Check if zip, exe, iso, etc.
Write-Output "Mounting ISO $file..."
$isoDrive = Mount-ISO $downloadFile


Write-Host "Installing WinSDK"
$setupPath = Join-Path $isoDrive "WinSDKSetup.exe"
Start-Process -Wait $setupPath "/features OptionId.UWPCpp /q"

Dismount-ISO $downloadFile