Skip to content

Instantly share code, notes, and snippets.

@bartvdbraak
Created December 12, 2024 10:36
Show Gist options
  • Save bartvdbraak/06160484b10ea03e1eb45a2c01cd006d to your computer and use it in GitHub Desktop.
Save bartvdbraak/06160484b10ea03e1eb45a2c01cd006d to your computer and use it in GitHub Desktop.
Write-Host "Attempting to download and install dependencies"
# Install VCLibs package
try {
Add-AppxPackage "https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx" -Verbose
} catch {
Write-Host "Failed to install VCLibs package. Error: $_" -ForegroundColor Red
exit 1
}
# Fetch the latest Microsoft.UI.Xaml package from NuGet
try {
$xamlVersion = "2.8.6" # Replace with dynamic fetch if required
$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest -Uri "https://www.nuget.org/api/v2/package/Microsoft.UI.Xaml/$xamlVersion" -OutFile "microsoft.ui.xaml.$xamlVersion.zip" -ErrorAction Stop
} catch {
Write-Host "Failed to download XAML package. Error: $_" -ForegroundColor Red
exit 1
}
# Extract and install XAML package
try {
Expand-Archive ".\microsoft.ui.xaml.$xamlVersion.zip" -Force -ErrorAction Stop
Add-AppPackage ".\microsoft.ui.xaml.$xamlVersion\tools\AppX\x64\Release\Microsoft.UI.Xaml.$xamlVersion.appx" -Verbose
} catch {
Write-Host "Failed to extract or install XAML package. Error: $_" -ForegroundColor Red
exit 1
}
Write-Host "Dependencies installed successfully."
# Fetch the latest Winget release from GitHub
Write-Host "Attempting to download and install Winget"
try {
$wingetApiUrl = "https://api.github.com/repos/microsoft/winget-cli/releases/latest"
$wingetRelease = Invoke-RestMethod -Uri $wingetApiUrl -UseBasicParsing
$wingetAsset = $wingetRelease.assets | Where-Object { $_.name -like "*.msixbundle" }
$licenseAsset = $wingetRelease.assets | Where-Object { $_.name -like "*.xml" }
if (-not $wingetAsset -or -not $licenseAsset) {
throw "Winget release assets not found."
}
$wingetPackageUrl = $wingetAsset.browser_download_url
$licenseUrl = $licenseAsset.browser_download_url
Invoke-WebRequest -Uri $wingetPackageUrl -OutFile ".\Winget.msixbundle" -ErrorAction Stop
Invoke-WebRequest -Uri $licenseUrl -OutFile ".\Winget_License.xml" -ErrorAction Stop
} catch {
Write-Host "Failed to download Winget package. Error: $_" -ForegroundColor Red
exit 1
}
# Install Winget package
try {
Add-AppxProvisionedPackage -Online -PackagePath ".\Winget.msixbundle" -LicensePath ".\Winget_License.xml" -Verbose
} catch {
Write-Host "Failed to install Winget package. Error: $_" -ForegroundColor Red
exit 1
}
Write-Host "Winget installed successfully."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment