| 1 | #Requires -RunAsAdministrator |
| 2 | |
| 3 | [cmdletbinding(PositionalBinding = $false)] |
| 4 | param ( |
| 5 | [ValidateSet("Debug", "Release")][string]$BuildType = "Debug", |
| 6 | [string]$BuildOutputPath = [string](Get-Location), |
| 7 | [string]$PackageCertPath = $null, |
| 8 | [parameter(ValueFromRemainingArguments = $true)] |
| 9 | [string[]]$MsiArgs |
| 10 | ) |
| 11 | |
| 12 | $ErrorActionPreference = "Stop" |
| 13 | |
| 14 | $processorArchitecture = (Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment').PROCESSOR_ARCHITECTURE |
| 15 | $Platform = switch -Wildcard ($processorArchitecture) { |
| 16 | '*ARM64*' { 'arm64' } |
| 17 | '*AMD64*' { 'X64' } |
| 18 | default { throw "Failed to determine system architecture: $processorArchitecture" } |
| 19 | } |
| 20 | |
| 21 | $PackagePath = "$BuildOutputPath\bin\$Platform\$BuildType\wsl.msi" |
| 22 | |
| 23 | # msiexec.exe doesn't like symlinks, so use the canonical path |
| 24 | $Target = (Get-ChildItem $PackagePath).Target |
| 25 | if ($Target) |
| 26 | { |
| 27 | $PackagePath = $Target |
| 28 | } |
| 29 | |
| 30 | Write-Host -ForegroundColor Green "Installing: $PackagePath " |
| 31 | |
| 32 | $MSIArguments = @( |
| 33 | "/i" |
| 34 | $PackagePath |
| 35 | "/qn" |
| 36 | "/norestart" |
| 37 | ) |
| 38 | |
| 39 | if ($MsiArgs) |
| 40 | { |
| 41 | $MSIArguments += $MsiArgs |
| 42 | } |
| 43 | |
| 44 | $exitCode = (Start-Process -Wait "msiexec.exe" -ArgumentList $MSIArguments -NoNewWindow -PassThru).ExitCode |
| 45 | if ($exitCode -Ne 0) |
| 46 | { |
| 47 | Write-Host "Failed to install package: $exitCode" |
| 48 | exit 1 |
| 49 | } |
| 50 | |
| 51 | Write-Host -ForegroundColor Green "Package $PackagePath installed successfully" |