-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Issues with COM API and retrieving installed packages #4320
Comments
Hi I'm an AI powered bot that finds similar issues based off the issue title. Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you! Open similar issues:
Closed similar issues:
|
@marticliment if you debug, you will see the problem: its not added to the composit catalog option sadly. BUT it is because you use "append" instead of "add". Add adds the catalog to the composite options. But i tested, does not change anything. Still i get packages shown which are not from the "winget" catalog , but have a empty source. We need a working --source winget option for the COM API |
As of version 1.8.1791, this code seems to be working. Thanks @PatrickSchmidtSE for pointing into the right direction // var WinGetFactory = new WindowsPackageManagerElevatedFactory();
var WinGetFactory = new WindowsPackageManagerStandardFactory();
var WinGetManager = WinGetFactory.CreatePackageManager();
// CHANGE THIS INDEX
int selectedIndex = 0;
PackageCatalogReference installedSearchCatalogRef;
if (selectedIndex < 0)
{
installedSearchCatalogRef = WinGetManager.GetLocalPackageCatalog(LocalPackageCatalog.InstalledPackages);
}
else
{
PackageCatalogReference selectedRemoteCatalogRef = WinGetManager.GetPackageCatalogs().ToArray().ElementAt(selectedIndex);
Console.WriteLine($"Searching on package catalog {selectedRemoteCatalogRef.Info.Name} ");
CreateCompositePackageCatalogOptions createCompositePackageCatalogOptions = WinGetFactory.CreateCreateCompositePackageCatalogOptions();
createCompositePackageCatalogOptions.Catalogs.Add(selectedRemoteCatalogRef);
createCompositePackageCatalogOptions.CompositeSearchBehavior = CompositeSearchBehavior.LocalCatalogs;
installedSearchCatalogRef = WinGetManager.CreateCompositePackageCatalog(createCompositePackageCatalogOptions);
}
var ConnectResult = installedSearchCatalogRef.Connect();
if (ConnectResult.Status != ConnectResultStatus.Ok)
{
throw new Exception("WinGet: Failed to connect to local catalog.");
}
FindPackagesOptions findPackagesOptions = WinGetFactory.CreateFindPackagesOptions();
PackageMatchFilter filter = WinGetFactory.CreatePackageMatchFilter();
filter.Field = PackageMatchField.Id;
filter.Option = PackageFieldMatchOption.ContainsCaseInsensitive;
filter.Value = "";
findPackagesOptions.Filters.Add(filter);
var TaskResult = ConnectResult.PackageCatalog.FindPackages(findPackagesOptions);
Console.WriteLine("Begin enumeration");
foreach (var match in TaskResult.Matches.ToArray())
{
if (match.CatalogPackage.DefaultInstallVersion != null)
Console.WriteLine($"Package {match.CatalogPackage.Name} is available Online: " + match.CatalogPackage.DefaultInstallVersion.PackageCatalog.Info.Name);
//else
//Console.WriteLine("Package is local only: " + match.CatalogPackage.Id);
}
Console.WriteLine("End enumeration"); |
Brief description of your issue
I have been trying to implement native WinGet support (WinGet COM API) on a NET/C# App (WingetUI), and I am experiencing issues when fetching installed packages.
More specifically, WinGet does not identify which packages are available on WinGet repositories, and all of the packages are listed as local only.
Running
winget list
shows the correct package sources on the right of package (nothing is shown if package is local,winget
ormsstore
otherwhise).Note: Packages do load and the list of installed packages is correct; and searching on remote catalogs works flawlessly.
Steps to reproduce
Expected behavior
WinGet identifying the online packages as such when loading a local composite catalog, so they have a valid
DefaultInstallVersion
and online information can be retieved (update date, origin, newer versions, etc.)Actual behavior
WinGet does not detect online packages as such. IDs are not reported properly and packages do have a null
DefaultInstallVersion
property.Interestingly, the same code works flawlessly on a WinRT/C++ environment (this is from SampleWinGetCaller, tested and working flawlessly):
Environment
The text was updated successfully, but these errors were encountered: