microsoft / winget-cli

WinGet is the Windows Package Manager. This project includes a CLI (Command Line Interface), PowerShell modules, and a COM (Component Object Model) API (Application Programming Interface).
https://learn.microsoft.com/windows/package-manager/
MIT License
23.35k stars 1.45k forks source link

Exact match for Moniker not being selected for install #3547

Open Trenly opened 1 year ago

Trenly commented 1 year ago

Brief description of your issue

When attempting an install, winget tries to select the best package matching user intent. This is done by assessing for exact matches on Moniker, ID, Name, and in some cases (such as uninstall) product code. If an exact match is found, the package is assumed to be the user intent and is selected for install.

The logic for this appears to be broken ~when both the msstore source and the winget source are enabled.~

Steps to reproduce

Running winget search will provide a list of the packages matched by the search and what field they were matched on if the match was not part of the name or package identifier. winget search uses a substring match on the Name and Package identifier by default, but a case insensitive match on monikers, commands, tags, etc.

The specific reproduction steps rely on the Google Chrome package. Running winget search chrome - WinGet-2023-08-23-10-23-37.093.log

PS C:\Windows\system32> winget search chrome --verbose
Name                                            Id                         Version        Match                 Source
-----------------------------------------------------------------------------------------------------------------------
DC Browser - Chrome and IE kernels              XP890QTFL1X0D0             Unknown                              msstore
DC Browser - Chrome and IE kernel               XP8BV7F2CT4LDK             Unknown                              msstore
Google Chrome                                   Google.Chrome              116.0.5845.111 Moniker: chrome       winget
Dichromate                                      Dichromate.Browser         110.0.5481.178 Command: chrome       winget
Google Chrome Dev                               Google.Chrome.Dev          117.0.5938.0   Command: chrome       winget
Google Chrome Beta                              Google.Chrome.Beta         117.0.5938.11  Command: chrome       winget
Chrome Remote Desktop Host                      Google.ChromeRemoteDesktop 112.0.5615.26  Tag: chrome           winget
Ginger Chrome                                   Saxo_Broko.GingerChrome    93.0.4529.0                          winget
<Results truncated for clarity>

From the search, it is clear that the first two entries are substring matches on the Name, the third entry is an exact match on moniker and substring matches on the Name and Package Identifier, and so on and so forth. Each entry in the list can be correlated to a match type.


Running winget install chrome - WinGet-2023-08-23-10-24-04.956.log

PS C:\Windows\system32> winget install chrome --verbose
Multiple packages found matching input criteria. Please refine the input.
Name                               Id             Source
---------------------------------------------------------
DC Browser - Chrome and IE kernels XP890QTFL1X0D0 msstore
Google Chrome                      Google.Chrome  winget

Expected behavior

Because the package Google.Chrome from the winget source had an exact match on moniker, and there were no exact matches on Name or Package Identifier from any source, the Google.Chrome package should be selected for install.

Actual behavior

Multiple packages are being found as matching user intent - the package XP890QTFL1X0D0 from the msstore source, and Google.Chrome from the winget source.

Based on the results from winget show, the package XP890QTFL1X0D0 is only a substring match on the package name, whereas Google.Chrome is an exact match on the moniker. Because of the exact match on the moniker, this package should be selected for user intent above any substring matches on name or identifier.

Environment

PS C:\Windows\system32> winget --info
Windows Package Manager (Preview) v1.6.2291-preview
Copyright (c) Microsoft Corporation. All rights reserved.

Windows: Windows.Desktop v10.0.19041.3086
System Architecture: X64
Package: Microsoft.DesktopAppInstaller v1.21.2291.0

Winget Directories
-------------------------------------------------------------------------------------------------------------------------------
Logs                               %LOCALAPPDATA%\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\DiagOutputDir
User Settings                      %LOCALAPPDATA%\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\settings.json
Portable Links Directory (User)    %LOCALAPPDATA%\Microsoft\WinGet\Links
Portable Links Directory (Machine) C:\Program Files\WinGet\Links
Portable Package Root (User)       %LOCALAPPDATA%\Microsoft\WinGet\Packages
Portable Package Root              C:\Program Files\WinGet\Packages
Portable Package Root (x86)        C:\Program Files (x86)\WinGet\Packages
Installer Downloads                %USERPROFILE%\Downloads

Links
---------------------------------------------------------------------------
Privacy Statement   https://aka.ms/winget-privacy
License Agreement   https://aka.ms/winget-license
Third Party Notices https://aka.ms/winget-3rdPartyNotice
Homepage            https://aka.ms/winget
Windows Store Terms https://www.microsoft.com/en-us/storedocs/terms-of-sale

Admin Setting                             State
--------------------------------------------------
LocalManifestFiles                        Enabled
BypassCertificatePinningForMicrosoftStore Disabled
InstallerHashOverride                     Disabled
LocalArchiveMalwareScanOverride           Enabled
Trenly commented 1 year ago

This also happens with packages within the same source - WinGet-2023-08-23-11-51-18.876.log

PS C:\WINDOWS\system32> winget search openjdk --verbose
Name                                       Id                             Version     Match            Source
-------------------------------------------------------------------------------------------------------------
ojdkbuild OpenJDK                          ojdkbuild.ojdkbuild            1.8.3321.9                   winget
Microsoft Build of OpenJDK with Hotspot 17 Microsoft.OpenJDK.17           17.0.8.7    Moniker: openjdk winget
Java SE Development Kit 20                 Oracle.JDK.20                  20.0.1.0    Tag: openjdk     winget
Java SE Development Kit 18                 Oracle.JDK.18                  18.0.2.1    Tag: openjdk     winget
Java SE Development Kit 17                 Oracle.JDK.17                  17.0.8.0    Tag: openjdk     winget
ojdkbuild OpenJDK JRE 17                   ojdkbuild.openjdk.17.jre       17.0030.6.1 Tag: openjdk     winget
ojdkbuild OpenJDK 17                       ojdkbuild.openjdk.17.jdk       17.0030.6.1 Tag: openjdk     winget
OpenJDK JRE 11                             ojdkbuild.openjdk.11.jre       11.0.15.1   Tag: openjdk     winget
OpenJDK 11                                 ojdkbuild.openjdk.11.jdk       11.0.15.1   Tag: openjdk     winget
<Results truncated for clarity>

WinGet-2023-08-23-11-51-36.391.log

PS C:\WINDOWS\system32> winget install openjdk --verbose
Multiple packages found matching input criteria. Please refine the input.
Name                                       Id                   Source
----------------------------------------------------------------------
ojdkbuild OpenJDK                          ojdkbuild.ojdkbuild  winget
Microsoft Build of OpenJDK with Hotspot 17 Microsoft.OpenJDK.17 winget
SimonCropp commented 1 year ago

can confirm with edge

winget uninstall --name "Microsoft Edge" --disable-interactivity --exact --silent --accept-source-agreements.
  ExitCode: -1978335210
  Output: Multiple installed packages found matching input criteria. Please refine the input.
Name           Id
-----------------------------------------------------------
Microsoft Edge Microsoft.Edge
Microsoft Edge Microsoft.MicrosoftEdge.Stable_8wekyb3d8bbwe
Trenly commented 1 year ago

can confirm with edge

It looks like the issue you're having with edge is expected behavior and is not related to the moniker issue. Because you're using the uninstall command, the list of packages is specific to what is currently installed on your machine, not what is available in the source. It is possible to have both Microsoft.Edge and Microsoft.MicrosoftEdge.Stable_8wekyb3d8bbwe installed at the same time. You specifically used the --name parameter and since both packages have the same name it cannot disambiguate between them. This is expected because both of them are an exact match. If you specify winget uninstall --id Microsoft.MicrosoftEdge.Stable_8wekyb3d8bbwe it should be able to uninstall without issue.

michaelmhoffman commented 1 year ago

I have a similar issue with the python3 moniker, even when specifying --exact --moniker

> winget install --exact --moniker python3
Multiple packages found matching input criteria. Please refine the input.
Name        Id                 Source
-------------------------------------
Python 3.11 Python.Python.3.11 winget
Python 3.12 Python.Python.3.12 winget

Presumably this is because Python.Python.3.11 also has the python3.11 moniker which python3 partially matches.