@@ -275,6 +275,64 @@ public IReadOnlyCollection<Package> FindPackagesById(
275275 return packages . ToList ( ) ;
276276 }
277277
278+ public IReadOnlyCollection < Package > FindLatestVersionsById (
279+ string id ,
280+ string includeVersion ,
281+ bool includePackageRegistration ,
282+ bool includeDeprecations ,
283+ bool includeSupportedFrameworks ,
284+ int maxCount )
285+ {
286+ if ( id == null )
287+ {
288+ throw new ArgumentNullException ( nameof ( id ) ) ;
289+ }
290+
291+ if ( maxCount < 1 )
292+ {
293+ throw new ArgumentOutOfRangeException ( nameof ( maxCount ) , "Max count must be greater than 0." ) ;
294+ }
295+
296+ var packages = GetPackagesByIdQueryable (
297+ id ,
298+ includeLicenseReports : false ,
299+ includePackageRegistration : includePackageRegistration ,
300+ includeUser : false ,
301+ includeSymbolPackages : false ,
302+ includeDeprecations : includeDeprecations ,
303+ includeDeprecationRelationships : false ,
304+ includeSupportedFrameworks : includeSupportedFrameworks )
305+ . OrderByDescending ( p => p . Created )
306+ . Take ( maxCount )
307+ . ToList ( ) ;
308+
309+ if ( ! string . IsNullOrWhiteSpace ( includeVersion ) && ! packages . Any ( p => p . NormalizedVersion == includeVersion ) )
310+ {
311+ var requiredPackage = GetPackagesByIdQueryable (
312+ id ,
313+ includeLicenseReports : false ,
314+ includePackageRegistration : includePackageRegistration ,
315+ includeUser : false ,
316+ includeSymbolPackages : false ,
317+ includeDeprecations : includeDeprecations ,
318+ includeDeprecationRelationships : false ,
319+ includeSupportedFrameworks : includeSupportedFrameworks )
320+ . Where ( p => p . NormalizedVersion == includeVersion )
321+ . SingleOrDefault ( ) ;
322+
323+ if ( requiredPackage is not null )
324+ {
325+ if ( packages . Count >= maxCount )
326+ {
327+ packages . RemoveAt ( packages . Count - 1 ) ;
328+ }
329+ packages . Add ( requiredPackage ) ;
330+ }
331+ }
332+
333+ return packages ;
334+ }
335+
278336 public virtual Package FindPackageByIdAndVersion (
279337 string id ,
280338 string version ,
0 commit comments