mirror of https://github.com/microsoft/WSL
test: fix and issue with the test-setup.ps1 script that was preventing it from being run from some version of powershell (#13834)
Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>
This commit is contained in:
parent
00b76b1d4b
commit
7f8422654e
|
|
@ -71,23 +71,41 @@ 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
|
||||
}
|
||||
finally
|
||||
{
|
||||
Remove-Item -Path .\private-wsl.cert
|
||||
catch {
|
||||
# Fallback: manually import the certificate and trust it
|
||||
Write-Host "Attempting to import package certificate..."
|
||||
$signature = Get-AuthenticodeSignature -LiteralPath $Package
|
||||
if (-not $signature.SignerCertificate) {
|
||||
Write-Error "Package is not signed or has no certificate. Cannot import certificate."
|
||||
exit 1
|
||||
}
|
||||
|
||||
$cert = $signature.SignerCertificate
|
||||
$certPath = Join-Path $env:TEMP "wsl-package-cert.cer"
|
||||
try {
|
||||
$cert | Export-Certificate -FilePath $certPath | Out-Null
|
||||
Import-Certificate -FilePath $certPath -CertStoreLocation Cert:\LocalMachine\Root | Out-Null
|
||||
Write-Host "Certificate imported successfully. Retrying package installation..."
|
||||
}
|
||||
finally {
|
||||
Remove-Item -Path $certPath -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
# Retry installation after importing certificate
|
||||
Add-AppxPackage $Package -ErrorAction Stop
|
||||
}
|
||||
}
|
||||
|
||||
Add-AppxPackage $Package
|
||||
else {
|
||||
Add-AppxPackage $Package -ErrorAction Stop
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Write-Host $_
|
||||
Get-AppPackageLog -All
|
||||
Write-Host "Error installing package: $_"
|
||||
Get-AppPackageLog | Select-Object -First 64 | Format-List
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue