diff --git a/src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/BuildAssetsUtils.cs b/src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/BuildAssetsUtils.cs index 9de48fec63a..7b597c90937 100644 --- a/src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/BuildAssetsUtils.cs +++ b/src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/BuildAssetsUtils.cs @@ -722,12 +722,24 @@ private static bool Exists(this Lazy package) private static IEnumerable WithExtension(this IList items, string extension) { - if (items == null) + if (items == null || items.Count == 0) { return Enumerable.Empty(); } - return items.Where(c => extension.Equals(Path.GetExtension(c.Path), StringComparison.OrdinalIgnoreCase)); + return FilterExtensions(items, extension); + + static IEnumerable FilterExtensions(IList items, string extension) + { + for (int i = 0; i < items.Count; ++i) + { + var item = items[i]; + if (extension.Equals(Path.GetExtension(item.Path), StringComparison.OrdinalIgnoreCase)) + { + yield return item; + } + } + } } private static string GetMatchingFrameworkStrings(PackageSpec spec, NuGetFramework framework)