[PR #17614] Use WinGet API to improve Quick Fix results #31295

Open
opened 2026-01-31 09:46:24 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/microsoft/terminal/pull/17614

State: closed
Merged: Yes


Summary of the Pull Request

Improves Quick Fix's suggestions to use WinGet API and actually query winget for packages based on the missing command.

To interact with the WinGet API, we need the Microsoft.WindowsPackageManager.ComInterop NuGet package. Microsoft.WindowsPackageManager.ComInterop.Additional.targets is used to copy over the winmd into CascadiaPackage. The build variable TerminalWinGetInterop is used to import the package properly.

WindowsPackageManagerFactory is used as a centralized way to generate the winget objects. Long-term, we may need to do manual activation for elevated sessions, which this class can easily be extended to support. In the meantime, we'll just use the normal winrt::create_instance on all sessions.

In TerminalPage, we conduct the search asynchronously when a missing command was found. Search results are limited to 20 packages. We try to retrieve packages with the following filters set, then fallback into the next step:

  1. PackageMatchField::Command, PackageFieldMatchOption::StartsWithCaseInsensitive
  2. PackageMatchField::Name, PackageFieldMatchOption::ContainsCaseInsensitive
  3. PackageMatchField::Moniker, PackageFieldMatchOption::ContainsCaseInsensitive

This aligns with the Microsoft.WinGet.CommandNotFound PowerShell module (link to relevant code).

Closes #17378
Closes #17631
Support for elevated sessions tracked in #17677

References

Validation Steps Performed

  • unelevated sessions --> winget query performed and presented
  • elevated sessions --> nothing happens (got rid of winget install {} suggestion)
**Original Pull Request:** https://github.com/microsoft/terminal/pull/17614 **State:** closed **Merged:** Yes --- ## Summary of the Pull Request Improves Quick Fix's suggestions to use WinGet API and actually query winget for packages based on the missing command. To interact with the WinGet API, we need the `Microsoft.WindowsPackageManager.ComInterop` NuGet package. `Microsoft.WindowsPackageManager.ComInterop.Additional.targets` is used to copy over the winmd into CascadiaPackage. The build variable `TerminalWinGetInterop` is used to import the package properly. `WindowsPackageManagerFactory` is used as a centralized way to generate the winget objects. Long-term, we may need to do manual activation for elevated sessions, which this class can easily be extended to support. In the meantime, we'll just use the normal `winrt::create_instance` on all sessions. In `TerminalPage`, we conduct the search asynchronously when a missing command was found. Search results are limited to 20 packages. We try to retrieve packages with the following filters set, then fallback into the next step: 1. `PackageMatchField::Command`, `PackageFieldMatchOption::StartsWithCaseInsensitive` 2. `PackageMatchField::Name`, `PackageFieldMatchOption::ContainsCaseInsensitive` 3. `PackageMatchField::Moniker`, `PackageFieldMatchOption::ContainsCaseInsensitive` This aligns with the Microsoft.WinGet.CommandNotFound PowerShell module ([link to relevant code](https://github.com/microsoft/winget-command-not-found/blob/9bc83617b94f6dc88e1fc9599e1c859bc3adf96f/src/WinGetCommandNotFoundFeedbackPredictor.cs#L165-L202)). Closes #17378 Closes #17631 Support for elevated sessions tracked in #17677 ## References - https://github.com/microsoft/winget-cli/blob/master/src/Microsoft.Management.Deployment/PackageManager.idl: winget object documentation ## Validation Steps Performed - [X] unelevated sessions --> winget query performed and presented - [X] elevated sessions --> nothing happens (got rid of `winget install {}` suggestion)
claunia added the pull-request label 2026-01-31 09:46:24 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#31295