Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Winget not installing #13

Closed
MrAbidPatel opened this issue Jul 25, 2023 · 12 comments
Closed

Winget not installing #13

MrAbidPatel opened this issue Jul 25, 2023 · 12 comments

Comments

@MrAbidPatel
Copy link

I've tried to run the script on several PCs. Not had any issues historically until yesterday. Now I just can't get winget to install. I get the same output as the readme. Failed getting latest UI.Xaml... Using hardcoded version 2.8.4 etc

However, despite many reboots, I just cannot get winget to install anymore.

I've tried 3 different builds on Windows 10 (Windows 10 Education - 22H2)

  1. Custom ISO updated to April 2023 (NTLite)
  2. Custom ISO updated to July 2023 (NTLite)
  3. Untouched ISO downloaded directly from VLSC - Updated July 2023

Also tried forcing the install using Chris Titus' script and I just get the message "Winget install failed".

Any ideas?

@asheroto
Copy link
Owner

This may sound dumb, but try it today. haha...

For some reason, nuget.org fails more often that you'd think. Sometimes it doesn't work for a second, minute, or hours. It sounds strange, but even when I was developing this script, I kept running into the same issue. Failed getting UI.Xaml. I changed nothing, and retried an hour later, and it worked.

Other than hosting the file on GitHub, waiting seems to be the solution. Let me know if it's working now for you. If not, maybe I will end up hosting it on GitHub.

@asheroto
Copy link
Owner

By the way, I just tried it today and it works. :-) So we'll see...

@MrAbidPatel
Copy link
Author

I still can't get winget to install. This is the output that I get...

WARNING: Failed getting latest Microsoft.UI.Xaml version from API                                                       
https://api.nuget.org/v3-flatcontainer/Microsoft.UI.Xaml/index.json
WARNING: Using the hardcoded version 2.8.4

##################################
# Downloading Xaml nupkg file... #
##################################

Downloading: https://www.nuget.org/api/v2/package/Microsoft.UI.Xaml/2.8.4
Saving as  : C:\Users\Abid\AppData\Local\Temp\Microsoft.UI.Xaml.2.8.4.nupkg.zip

Expand into: C:\Users\Abid\AppData\Local\Temp\Microsoft.UI.Xaml.2.8.4

##########################################
# Downloading & installing x64 VCLibs... #
##########################################


##########################
# Installing x64 XAML... #
##########################

Installing Appx Packages In: C:\Users\Abid\AppData\Local\Temp\Microsoft.UI.Xaml.2.8.4\tools\AppX\x64\Release

Installing Appx Package: Microsoft.UI.Xaml.2.8.appx

#########################
# Downloading winget... #
#########################

Retrieving download URL for winget from GitHub...

Downloading: https://github.com/microsoft/winget-cli/releases/download/v1.5.1881/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle
Saving as  : C:\Users\Abid\AppData\Local\Temp\winget.msixbundle


Downloading: https://github.com/microsoft/winget-cli/releases/download/v1.5.1881/c6bee58ade21451eb54dc52e559a314c_License1.xml
Saving as  : C:\Users\Abid\AppData\Local\Temp\license1.xml


########################
# Installing winget... #
########################

wingetPath       : C:\Users\Abid\AppData\Local\Temp\winget.msixbundle
wingetLicensePath: C:\Users\Abid\AppData\Local\Temp\license1.xml


#################################################################################################
# Checking and adding WindowsApps directory to PATH variable for current user if not present... #
#################################################################################################

C:\Users\Abid\AppData\Local\Microsoft\WindowsApps already present in PATH variable for current user, skipping.

##################
# Cleaning up... #
##################


##########################
# Installation complete! #
##########################


##############################################################
# Please restart your computer to complete the installation. #
##############################################################

Despite several reboots, when I try to run winget, I get the following error:

PS C:\Windows\system32> winget
winget : The term 'winget' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ winget
+ ~~~~~~
    + CategoryInfo          : ObjectNotFound: (winget:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Still can't get it to work via the script :(

@asheroto
Copy link
Owner

asheroto commented Jul 27, 2023

Does winget.exe exist in

C:\Users\Abid\AppData\Local\Microsoft\WindowsApps

Or the current user's apps that you're installing winget with?

@MrAbidPatel
Copy link
Author

No, winget doesn't exist in that folder. There is a "Microsoft.DesktopAppInstaller_8wekyb3d8bbwe" folder in that location, but it only has 3 files inside it:

python.exe
python3.7.exe
python3.exe

@boydfields
Copy link

Same issue here.

@asheroto
Copy link
Owner

asheroto commented Jul 27, 2023

Can you both please run winver from the command line / Start > Run to determine the exact Windows version? Kindly paste a screenshot. I'll investigate further.

@MrAbidPatel
Copy link
Author

Can you both please run winver from the command line / Start > Run to determine the exact Windows version? Kindly paste a screenshot. I'll investigate further.

The filename of the ISO I downloaded from the VLSC:
SW_DVD9_Win_Pro_10_22H2.9_64BIT_Eng_Intl_Pro_Ent_EDU_N_MLF_X23-51693.ISO

Here's the winver:

image

@MrAbidPatel
Copy link
Author

Chris Titus just fixed this in his latest update.

$ErrorActionPreference = "Stop"
$apiLatestUrl = 'https://api.github.com/repos/microsoft/winget-cli/releases/latest'
$tempFolder = $env:TEMP

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$WebClient = New-Object System.Net.WebClient


function Update-EnvironmentVariables {
  foreach($level in "Machine","User") {
    [Environment]::GetEnvironmentVariables($level).GetEnumerator() | % {
        # For Path variables, append the new values, if they're not already in there
        if($_.Name -match 'Path$') {
          $_.Value = ($((Get-Content "Env:$($_.Name)") + ";$($_.Value)") -split ';' | Select -unique) -join ';'
        }
        $_
    } | Set-Content -Path { "Env:$($_.Name)" }
  }
}

function Get-LatestUrl {
  ((Invoke-WebRequest $apiLatestUrl -UseBasicParsing | ConvertFrom-Json).assets | Where-Object { $_.name -match '^Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle$' }).browser_download_url
}

function Get-LatestHash {
  $shaUrl = ((Invoke-WebRequest $apiLatestUrl -UseBasicParsing | ConvertFrom-Json).assets | Where-Object { $_.name -match '^Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.txt$' }).browser_download_url

  $shaFile = Join-Path -Path $tempFolder -ChildPath 'Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.txt'
  $WebClient.DownloadFile($shaUrl, $shaFile)

  Get-Content $shaFile
}

# Hide the progress bar of Invoke-WebRequest
$oldProgressPreference = $ProgressPreference
$ProgressPreference = 'SilentlyContinue'

$desktopAppInstaller = @{
  fileName = 'Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle'
  url      = $(Get-LatestUrl)
  hash     = $(Get-LatestHash)
}

$vcLibsUwp = @{
  fileName = 'Microsoft.VCLibs.x64.14.00.Desktop.appx'
  url      = 'https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx'
  hash     = '6602159c341bafea747d0edf15669ac72df8817299fbfaa90469909e06794256'
}
$uiLibs = @{
    nupkg = @{
        fileName = 'microsoft.ui.xaml.2.7.0.nupkg'
        url = 'https://www.nuget.org/api/v2/package/Microsoft.UI.Xaml/2.7.0'
        hash = "422FD24B231E87A842C4DAEABC6A335112E0D35B86FAC91F5CE7CF327E36A591"
    }
    uwp = @{
        fileName = 'Microsoft.UI.Xaml.2.7.appx'
    }
}
$uiLibs.uwp.file = $PWD.Path + '\' + $uiLibs.uwp.fileName
$uiLibs.uwp.zipPath = '*/x64/*/' + $uiLibs.uwp.fileName

$dependencies = @($desktopAppInstaller, $vcLibsUwp, $uiLibs.nupkg)

foreach ($dependency in $dependencies) {
  $dependency.file = $dependency.fileName
  iwr $dependency.url -OutFile $dependency.file
}

$uiLibs.nupkg.file = $PSScriptRoot + '\' + $uiLibs.nupkg.fileName
Add-Type -Assembly System.IO.Compression.FileSystem
$uiLibs.nupkg.zip = [IO.Compression.ZipFile]::OpenRead($uiLibs.nupkg.file)
$uiLibs.nupkg.zipUwp = $uiLibs.nupkg.zip.Entries | Where-Object { $_.FullName -like $uiLibs.uwp.zipPath }
[System.IO.Compression.ZipFileExtensions]::ExtractToFile($uiLibs.nupkg.zipUwp, $uiLibs.uwp.file, $true)
$uiLibs.nupkg.zip.Dispose()

Add-AppxPackage -Path $desktopAppInstaller.file -DependencyPath $vcLibsUwp.file,$uiLibs.uwp.file

rm $desktopAppInstaller.file
rm $vcLibsUwp.file
rm $uiLibs.nupkg.file
rm $uiLibs.uwp.file
Write-Host "WinGet installed!" -ForegroundColor Green
$ProgressPreference = $oldProgressPreference
Update-EnvironmentVariables
# winget install Microsoft.WindowsTerminal
# winget install ubuntu

@asheroto
Copy link
Owner

Thanks for the info. This should help. I have been a bit busy this week but I definitely will look at this soon.

@asheroto
Copy link
Owner

Update 2023-07-31:

I'm working on a fix for this and should have something in the next day or so.

@asheroto
Copy link
Owner

asheroto commented Aug 1, 2023

Thanks to everyone for the help. I have made some major changes to the script. Everything should be working now.

Please update the script again using

Install-Script winget-install -Force

And re-run

@asheroto asheroto closed this as completed Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants