From d8a22207be2301847c49457388a45c4d2239d059 Mon Sep 17 00:00:00 2001 From: Martin Ruiz Date: Thu, 6 Oct 2022 09:47:16 -0700 Subject: [PATCH] Fix empty combobox when package is not present in project file (#4844) --- .../NuGet.PackageManagement.UI/Models/DetailControlModel.cs | 2 +- .../Models/PackageDetailControlModel.cs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/NuGet.Clients/NuGet.PackageManagement.UI/Models/DetailControlModel.cs b/src/NuGet.Clients/NuGet.PackageManagement.UI/Models/DetailControlModel.cs index 5d4ff25c18d..88e1ca9633e 100644 --- a/src/NuGet.Clients/NuGet.PackageManagement.UI/Models/DetailControlModel.cs +++ b/src/NuGet.Clients/NuGet.PackageManagement.UI/Models/DetailControlModel.cs @@ -842,7 +842,7 @@ protected void AddBlockedVersions(List blockedVersions) // add all the versions blocked to disable the update button foreach (var version in blockedVersions) { - _versions.Add(new DisplayVersion(version, string.Empty, isValidVersion: false)); + _versions.Add(new DisplayVersion(version, additionalInfo: null, isValidVersion: false)); } } diff --git a/src/NuGet.Clients/NuGet.PackageManagement.UI/Models/PackageDetailControlModel.cs b/src/NuGet.Clients/NuGet.PackageManagement.UI/Models/PackageDetailControlModel.cs index 812e74a1b3c..2303251d563 100644 --- a/src/NuGet.Clients/NuGet.PackageManagement.UI/Models/PackageDetailControlModel.cs +++ b/src/NuGet.Clients/NuGet.PackageManagement.UI/Models/PackageDetailControlModel.cs @@ -167,7 +167,7 @@ protected override Task CreateVersionsAsync(CancellationToken cancellationToken) var latestStableVersion = allVersionsAllowed.FirstOrDefault(v => !v.version.IsPrerelease); // Add installed version if the project is PackageReference - if (_nugetProjects.Any() && installedDependency != null && installedDependency.VersionRange != null && _nugetProjects.First().ProjectStyle.Equals(ProjectModel.ProjectStyle.PackageReference)) + if (_nugetProjects.Any() && installedDependency != null && installedDependency.VersionRange.OriginalString != null && _nugetProjects.First().ProjectStyle.Equals(ProjectModel.ProjectStyle.PackageReference)) { VersionRange installedVersionRange = VersionRange.Parse(installedDependency.VersionRange.OriginalString, true); NuGetVersion bestVersion = installedVersionRange.FindBestMatch(allVersionsAllowed.Select(v => v.version)); @@ -311,6 +311,7 @@ public override void OnSelectedVersionChanged() OnPropertyChanged(nameof(IsInstalledVersionTopLevel)); } + public bool IsSelectedVersionInstalled { get @@ -326,7 +327,7 @@ public bool IsInstallorUpdateButtonEnabled { get { - return SelectedVersion != null && !IsSelectedVersionInstalled; + return SelectedVersion != null && !IsSelectedVersionInstalled && !InstalledVersionIsAutoReferenced; } }