How do I install WinGet on Windows Server 2019?
Asked Answered
M

5

17

I'm trying to install WinGet on a Windows Server 2019 (Standard Edition, Version 1809, Build 17763), but I can't get it to work...

When trying the "install directly" link from this blog post I get the following link ms-appinstaller:?source=https://aka.ms/getwinget which my browser doesn't understand because I don't have the App Installer.

So I downloaded the Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.appxbundle from the GitHub releases page mentioned in the same blog post (which should contain both the App Installer and WinGet). Because my system doesn't get .appxbundle files I tried installing it using Powershell:

Add-AppxPackage ".\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.appxbundle"

But it complains that it misses Microsoft.VCLibs.140.00.UWPDesktop:

Add-AppxPackage : Deployment failed with HRESULT: 0x80073CF3, Package failed updates, 
dependency or conflict validation.
Windows cannot install package Microsoft.DesktopAppInstaller_1.11.11451.0_x64__8wekyb3d8bbwe 
because this package depends on a framework that could not be found. Provide the framework 
"Microsoft.VCLibs.140.00.UWPDesktop" published by "CN=Microsoft Corporation, O=Microsoft 
Corporation, L=Redmond, S=Washington, C=US", with neutral or x64 processor architecture and 
minimum version 14.0.29231.0, along with this package to install. The frameworks with name
"Microsoft.VCLibs.140.00.UWPDesktop" currently installed

Apparently, this is a "C++ Runtime framework packages for Desktop Bridge" that can also be downloaded as an appx; installing it first and then installing the DesktopAppInstaller/WinGet bundle goes without errors:

Add-AppxPackage ".\Microsoft.VCLibs.x64.14.00.Desktop.appx"
Add-AppxPackage ".\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.appxbundle"

However, at this point I seem to have the App Installer (as it now recognises the .appx/.appxbundle files), but not the WinGet client, because when I run it from a command prompt it tells me:

'winget' is not recognized as an internal or external command, operable program or batch file.

How can I get WinGet to work on a Windows Server 2019 machine?

Mitzimitzie answered 23/6, 2021 at 13:21 Comment(1)
For anyone else with the same problem, I just stumbled onto this thread: github.com/microsoft/winget-cli/issues/144Mitzimitzie
G
16

Actually, there is a workaround for installing this. Referencing one of the comments for winget issue #1861 we can see that all we have to do is download VCLibs, Microsoft.UI.XAML.2.8.6, install it using Add-AppxPackage, download Microsoft.DesktopInstaller and install that as well in order to run winget on a server.

Below is a slightly (not much) modified version of the comment referenced in #1861. It's modified to permit it to download the latest version of winget no matter what.

# Install VCLibs
Add-AppxPackage 'https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx'

# Install Microsoft.UI.Xaml (latest) from NuGet
Invoke-WebRequest -Uri https://www.nuget.org/api/v2/package/Microsoft.UI.Xaml/ -OutFile .\microsoft.ui.xaml.zip
Expand-Archive .\microsoft.ui.xaml.zip
Add-AppxPackage .\microsoft.ui.xaml\tools\AppX\x64\Release\Microsoft.UI.Xaml.2.8.appx

# Install the latest release of Microsoft.DesktopInstaller from GitHub
Invoke-WebRequest -Uri https://github.com/microsoft/winget-cli/releases/latest/download/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle -OutFile .\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle
Add-AppxPackage .\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle

If you're looking to use this, just ensure to run it in an empty directory.

Gassing answered 20/3, 2023 at 18:41 Comment(2)
To use it today you have to update the dependencies.. So update the code looking for latest version also in the nuget (nuget.org/api/v2/package/Microsoft.UI.Xaml/latest) or replace the version with the latest.Heptameter
@MarcoOrtali Thanks so much for that. Noted and updated accordingly.Gassing
C
7

The above workaround almost did it. I had to fix permissions:

TAKEOWN /F "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_1.19.10173.0_x64__8wekyb3d8bbwe" /R /A /D Y
ICACLS "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_1.19.10173.0_x64__8wekyb3d8bbwe" /grant Administrators:F /T

and also add to shell path. Within an existing Powershell instance:

$ResolveWingetPath = Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe"
    if ($ResolveWingetPath){
           $WingetPath = $ResolveWingetPath[-1].Path
    }
$ENV:PATH += ";$WingetPath"
Congregational answered 4/4, 2023 at 15:32 Comment(0)
C
3

Windows Server 2019, and Windows Server 2022 aren't supported. It may be possible to install the Windows Package Manager, but the dependencies aren't included in those SKUs.

https://github.com/microsoft/winget-cli/issues/754#issuecomment-902798802

edited:2024/03/26

The Microsoft.WinGet.Client PowerShell module has a Repair-WinGetPackageManager cmdlet which should bootstrap WinGet and its dependencies. The CLI App Execution Alias isn't supported on Windows Server 2019 though. With PowerShell 7 the majority of the other cmdlets will work even without WinGet installed, but a couple still call the CLI under the hood.

Catharine answered 7/10, 2021 at 14:30 Comment(0)
I
2

The better variant of @Jonathan's script - in case we don't know exactly version of DesktopAppInstaller:

$folderMask = "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*"
$folders = Get-ChildItem -Path $folderMask -Directory | Where-Object { $_.Name -like "*_x64_*" }
foreach ($folder in $folders) {
    $folderPath = $folder.FullName
    TAKEOWN /F $folderPath /R /A /D Y
    ICACLS $folderPath /grant Administrators:F /T
}
Insociable answered 27/8, 2023 at 9:56 Comment(0)
D
0

Above steps were very helpful but for me it worked as below. I had to update the versions for Microsoft.UI.Xaml and for my WIndows Server 2019 VM in Azure I had to also install VC++ x64 executable.

if (-not (Get-PackageProvider -Name NuGet) -or (Get-PackageProvider -Name NuGet).version -lt 2.8.5.201 ) {

    try {

        Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Confirm:$False -Force

    }

    catch {

        Write-Error -Message $_.Exception

    }

}



try {
    winget --version 
}

catch
 {

 # Install VC++ x64 executable

    Invoke-WebRequest -Uri https://aka.ms/vs/16/release/vc_redist.x64.exe -OutFile .\vc_redist.x64.exe
    Start-Process .\vc_redist.x64.exe /S -NoNewWindow -Wait -PassThru


    # Install Microsoft.UI.Xaml.2.8.6 from NuGet

    Invoke-WebRequest -Uri https://www.nuget.org/api/v2/package/Microsoft.UI.Xaml/2.8.6 -OutFile .\microsoft.ui.xaml.2.8.6.zip

    Expand-Archive .\microsoft.ui.xaml.2.8.6.zip -Force

    Add-AppxPackage .\microsoft.ui.xaml.2.8.6\tools\AppX\x64\Release\Microsoft.UI.Xaml.2.8.appx

   

    # Install the latest release of Microsoft.DesktopInstaller from GitHub

    Invoke-WebRequest -Uri https://github.com/microsoft/winget-cli/releases/latest/download/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle -OutFile .\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle

    Add-AppxPackage .\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle

    $ResolveWingetPath = Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe"
    if ($ResolveWingetPath){
           $WingetPath = $ResolveWingetPath[-1].Path
           $ENV:PATH += ";$WingetPath"
    }   
}
Dissemblance answered 11/4 at 8:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.