From 0d3446a6a2da90dcdc129411167e04aabfa08303 Mon Sep 17 00:00:00 2001 From: AmirMS <104940545+AmelBawa-msft@users.noreply.github.com> Date: Tue, 13 Aug 2024 14:36:59 -0700 Subject: [PATCH] Pinned WinGet packages are not loaded in Dev Home (#3596) --- .../Models/WinGetPackage.cs | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/services/DevHome.Services.WindowsPackageManager/Models/WinGetPackage.cs b/services/DevHome.Services.WindowsPackageManager/Models/WinGetPackage.cs index 02f28bd616..55817e8620 100644 --- a/services/DevHome.Services.WindowsPackageManager/Models/WinGetPackage.cs +++ b/services/DevHome.Services.WindowsPackageManager/Models/WinGetPackage.cs @@ -28,8 +28,8 @@ public WinGetPackage(ILogger logger, CatalogPackage package, bool requiresElevat // longer running). _logger = logger; Id = package.Id; - CatalogId = package.DefaultInstallVersion.PackageCatalog.Info.Id; - CatalogName = package.DefaultInstallVersion.PackageCatalog.Info.Name; + CatalogId = GetPackageVersionInfo(package).PackageCatalog.Info.Id; + CatalogName = GetPackageVersionInfo(package).PackageCatalog.Info.Name; UniqueKey = new(Id, CatalogId); Name = package.Name; AvailableVersions = package.AvailableVersions.Select(v => v.Version).ToList(); @@ -81,6 +81,22 @@ public WinGetPackageUri GetUri(string installVersion = null) return new(CatalogName, Id, uriOptions); } + private PackageVersionInfo GetPackageVersionInfo(CatalogPackage package) + { + // Pinned packages do not have a default install version set + if (package.DefaultInstallVersion != null) + { + return package.DefaultInstallVersion; + } + + if (package.AvailableVersions.Count > 0) + { + return package.GetPackageVersionInfo(package.AvailableVersions[0]); + } + + throw new ArgumentException($"Package {package.Name} does not have any versions"); + } + /// /// Gets the package metadata from the current culture name (e.g. 'en-US') /// @@ -94,7 +110,7 @@ private T GetMetadataValue(CatalogPackage package, Func