Add .NET fallback on Expand-Archive fail
The `Expand-Archive` cmdlet fails in localized Windows Sandbox environments (e.g., de-DE) because the `Microsoft.PowerShell.Archive` module cannot find its localization resources (`ArchiveResources.psd1`) in the minimal OS image.pull/13/head
parent
c33a3c70b7
commit
dce2153228
|
|
@ -126,7 +126,16 @@ if ($depsZipUrl) {
|
||||||
# Remove existing Dependencies folder and expand the zip
|
# Remove existing Dependencies folder and expand the zip
|
||||||
if (Test-Path $topDepsFolder) { Remove-Item -Path $topDepsFolder -Recurse -Force }
|
if (Test-Path $topDepsFolder) { Remove-Item -Path $topDepsFolder -Recurse -Force }
|
||||||
|
|
||||||
Expand-Archive -LiteralPath $depsZipPath -DestinationPath $topDepsFolder -Force
|
# Use Expand-Archive cmdlet by default because it's safe for constrained language mode. Fall back to .NET assembly if it fails.
|
||||||
|
try {
|
||||||
|
Expand-Archive -LiteralPath $depsZipPath -DestinationPath $topDepsFolder -Force -ErrorAction Stop
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Warning "Standard extraction failed, attempting .NET fallback. The error was: $($_.Exception.Message)"
|
||||||
|
# Fallback using .NET System.IO.Compression (Fixes issues in non-EN Windows Sandbox)
|
||||||
|
Add-Type -AssemblyName System.IO.Compression.FileSystem
|
||||||
|
[System.IO.Compression.ZipFile]::ExtractToDirectory($depsZipPath, $topDepsFolder)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else { Write-Warning "No $depsZipName found in $latestTag, skipping dependency download."; }
|
else { Write-Warning "No $depsZipName found in $latestTag, skipping dependency download."; }
|
||||||
|
|
||||||
|
|
@ -156,4 +165,3 @@ if ($removeMsStoreAsSource.IsPresent) {
|
||||||
# Automatically accept source agreements to avoid prompts. Mostly applies to msstore.
|
# Automatically accept source agreements to avoid prompts. Mostly applies to msstore.
|
||||||
winget list --accept-source-agreements | Out-Null
|
winget list --accept-source-agreements | Out-Null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue