Created
July 6, 2025 01:03
-
-
Save karlgluck/9716fcfdc185f4591537af036afd7f30 to your computer and use it in GitHub Desktop.
"winget" is not available in Windows Sandbox by default. This script adds it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set up working folder | |
$wingetFolder = "$env:TEMP\winget-install" | |
New-Item -ItemType Directory -Path $wingetFolder -Force | Out-Null | |
Set-Location $wingetFolder | |
# Dependency URLs (v1.11.400 as of mid-2024) | |
$urls = @{ | |
VCLibs = "https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx" | |
UIXaml = "https://www.nuget.org/api/v2/package/Microsoft.UI.Xaml/2.8.6" | |
AppInstaller = "https://github.com/microsoft/winget-cli/releases/download/v1.11.400/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" | |
} | |
# Helper to download a file | |
function Download-File { | |
param ( | |
[string]$Url, | |
[string]$Destination | |
) | |
Write-Host "Downloading $Url..." | |
Invoke-WebRequest -Uri $Url -OutFile $Destination | |
} | |
# Download VCLibs | |
$vclibsPath = "$wingetFolder\Microsoft.VCLibs.x64.14.00.appx" | |
Download-File -Url $urls.VCLibs -Destination $vclibsPath | |
# Download and extract Microsoft.UI.Xaml from NuGet | |
$nugetPkg = "$wingetFolder\Microsoft.UI.Xaml.2.8.6.nupkg" | |
$extractedXamlPath = "$wingetFolder\Xaml" | |
Download-File -Url $urls.UIXaml -Destination $nugetPkg | |
Add-Type -AssemblyName System.IO.Compression.FileSystem | |
[System.IO.Compression.ZipFile]::ExtractToDirectory($nugetPkg, $extractedXamlPath) | |
# Find the correct .appx inside the extracted NuGet package (x64) | |
$xamlAppx = Get-ChildItem "$extractedXamlPath" -Recurse -Filter *.appx | Where-Object { $_.Name -like "*x64*.appx" } | Select-Object -First 1 | |
if (-not $xamlAppx) { | |
throw "Microsoft.UI.Xaml .appx not found." | |
} | |
# Download App Installer bundle | |
$appInstallerPath = "$wingetFolder\AppInstaller.msixbundle" | |
Download-File -Url $urls.AppInstaller -Destination $appInstallerPath | |
# Install all in correct order | |
Write-Host "`nInstalling Microsoft.VCLibs..." | |
Add-AppxPackage -Path $vclibsPath | |
Write-Host "Installing Microsoft.UI.Xaml..." | |
Add-AppxPackage -Path $xamlAppx.FullName | |
Write-Host "Installing Microsoft.DesktopAppInstaller (winget)..." | |
Add-AppxPackage -Path $appInstallerPath | |
# Install WinGet now that we have the desktop app installer | |
Install-PackageProvider NuGet -Force | |
Set-PSRepository PSGallery -InstallationPolicy Trusted | |
Install-Module Microsoft.Winget.Client -Confirm:$False -Force -AllowClobber | |
Import-Module -Name Microsoft.Winget.Client | |
Repair-WingetPackageManager -Force -Latest -Verbose |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment