@@ -230,21 +230,44 @@ private void RemoveNugetAnalyzerReferences()
230230 }
231231 }
232232
233+ private void SelectNewestFrameworkPath ( string frameworkPath , string frameworkType , ISet < string > dllPaths , ISet < string > frameworkLocations )
234+ {
235+ var versionFolders = new DirectoryInfo ( frameworkPath )
236+ . EnumerateDirectories ( "*" , new EnumerationOptions { MatchCasing = MatchCasing . CaseInsensitive , RecurseSubdirectories = false } )
237+ . OrderByDescending ( d => d . Name ) // TODO: Improve sorting to handle pre-release versions.
238+ . ToArray ( ) ;
239+
240+ if ( versionFolders . Length > 1 )
241+ {
242+ var versions = string . Join ( ", " , versionFolders . Select ( d => d . Name ) ) ;
243+ progressMonitor . LogInfo ( $ "Found multiple { frameworkType } DLLs in NuGet packages at { frameworkPath } . Using the latest version ({ versionFolders [ 0 ] . Name } ) from: { versions } .") ;
244+ }
245+
246+ var selectedFrameworkFolder = versionFolders . FirstOrDefault ( ) ? . FullName ;
247+ if ( selectedFrameworkFolder is null )
248+ {
249+ progressMonitor . LogInfo ( $ "Found { frameworkType } DLLs in NuGet packages at { frameworkPath } , but no version folder was found.") ;
250+ selectedFrameworkFolder = frameworkPath ;
251+ }
252+
253+ dllPaths . Add ( selectedFrameworkFolder ) ;
254+ frameworkLocations . Add ( selectedFrameworkFolder ) ;
255+ progressMonitor . LogInfo ( $ "Found { frameworkType } DLLs in NuGet packages at { selectedFrameworkFolder } . Not adding installation directory.") ;
256+ }
257+
233258 private void AddNetFrameworkDlls ( ISet < string > dllPaths , ISet < string > frameworkLocations )
234259 {
235260 // Multiple dotnet framework packages could be present.
236261 // The order of the packages is important, we're adding the first one that is present in the nuget cache.
237262 var packagesInPrioOrder = FrameworkPackageNames . NetFrameworks ;
238263
239264 var frameworkPath = packagesInPrioOrder
240- . Select ( ( s , index ) => ( Index : index , Path : GetPackageDirectory ( s ) ) )
241- . FirstOrDefault ( pair => pair . Path is not null ) ;
265+ . Select ( ( s , index ) => ( Index : index , Path : GetPackageDirectory ( s ) ) )
266+ . FirstOrDefault ( pair => pair . Path is not null ) ;
242267
243268 if ( frameworkPath . Path is not null )
244269 {
245- dllPaths . Add ( frameworkPath . Path ) ;
246- frameworkLocations . Add ( frameworkPath . Path ) ;
247- progressMonitor . LogInfo ( $ "Found .NET Core/Framework DLLs in NuGet packages at { frameworkPath . Path } . Not adding installation directory.") ;
270+ SelectNewestFrameworkPath ( frameworkPath . Path , ".NET Framework" , dllPaths , frameworkLocations ) ;
248271
249272 for ( var i = frameworkPath . Index + 1 ; i < packagesInPrioOrder . Length ; i ++ )
250273 {
@@ -308,9 +331,7 @@ private void AddAspNetCoreFrameworkDlls(ISet<string> dllPaths, ISet<string> fram
308331 // First try to find ASP.NET Core assemblies in the NuGet packages
309332 if ( GetPackageDirectory ( FrameworkPackageNames . AspNetCoreFramework ) is string aspNetCorePackage )
310333 {
311- progressMonitor . LogInfo ( $ "Found ASP.NET Core in NuGet packages. Not adding installation directory.") ;
312- dllPaths . Add ( aspNetCorePackage ) ;
313- frameworkLocations . Add ( aspNetCorePackage ) ;
334+ SelectNewestFrameworkPath ( aspNetCorePackage , "ASP.NET Core" , dllPaths , frameworkLocations ) ;
314335 return ;
315336 }
316337
@@ -326,9 +347,7 @@ private void AddMicrosoftWindowsDesktopDlls(ISet<string> dllPaths, ISet<string>
326347 {
327348 if ( GetPackageDirectory ( FrameworkPackageNames . WindowsDesktopFramework ) is string windowsDesktopApp )
328349 {
329- progressMonitor . LogInfo ( $ "Found Windows Desktop App in NuGet packages.") ;
330- dllPaths . Add ( windowsDesktopApp ) ;
331- frameworkLocations . Add ( windowsDesktopApp ) ;
350+ SelectNewestFrameworkPath ( windowsDesktopApp , "Windows Desktop App" , dllPaths , frameworkLocations ) ;
332351 }
333352 }
334353
0 commit comments