Closed marticliment closed 3 months ago
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!
winget upgrade
. (#4158), similarity score: 0.77Note: You can give me feedback by thumbs upping or thumbs downing this comment.
@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
// Include WinGet Namespace using WindowsPackageManager.Interop;
namespace WingetTest { internal class Program { static public void Main(string[] args) { var WinGetFactory = new WindowsPackageManagerStandardFactory(); var WinGetManager = WinGetFactory.CreatePackageManager();
}
Environment