diff --git a/tools/test/test-setup.ps1 b/tools/test/test-setup.ps1 index 03fa804..9de355c 100644 --- a/tools/test/test-setup.ps1 +++ b/tools/test/test-setup.ps1 @@ -71,23 +71,45 @@ if ($Package) { try { if ($AllowUnsigned) { - # unfortunately -AllowUnsigned isn't supported on vb so we need to manually import the certificate and trust it. - (Get-AuthenticodeSignature $Package).SignerCertificate | Export-Certificate -FilePath private-wsl.cert | Out-Null - try - { - Import-Certificate -FilePath .\private-wsl.cert -CertStoreLocation Cert:\LocalMachine\Root | Out-Null + # Try to add with -AllowUnsigned first (supported in newer PowerShell) + try { + Add-AppxPackage $Package -AllowUnsigned -ErrorAction Stop + $installed = $true } - finally - { - Remove-Item -Path .\private-wsl.cert + catch { + # Fallback: manually import the certificate and trust it + try { + $cert = (Get-AuthenticodeSignature -LiteralPath $Package).SignerCertificate + if ($cert) { + $certPath = Join-Path $env:TEMP "private-wsl-$([guid]::NewGuid()).cert" + $cert | Export-Certificate -FilePath $certPath | Out-Null + try { + Import-Certificate -FilePath $certPath -CertStoreLocation Cert:\LocalMachine\Root | Out-Null + } + finally { + Remove-Item -Path $certPath -ErrorAction SilentlyContinue + } + } + } + catch { + Write-Warning "Could not import certificate: $_" + } + $installed = $false } } - Add-AppxPackage $Package + if (-not $installed) { + Add-AppxPackage $Package -ErrorAction Stop + } } catch { - Write-Host $_ - Get-AppPackageLog -All + Write-Host "Error installing package: $_" + # Only show recent relevant logs, not all historical logs + try { + Get-AppPackageLog -ActivityID * | Where-Object {$_.TimeCreated -gt (Get-Date).AddMinutes(-5)} | Select-Object -First 10 + } catch { + Write-Host "Could not retrieve app package logs" + } exit 1 } }