@@ -230,21 +230,44 @@ private void RemoveNugetAnalyzerReferences()
230
230
}
231
231
}
232
232
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
+
233
258
private void AddNetFrameworkDlls ( ISet < string > dllPaths , ISet < string > frameworkLocations )
234
259
{
235
260
// Multiple dotnet framework packages could be present.
236
261
// The order of the packages is important, we're adding the first one that is present in the nuget cache.
237
262
var packagesInPrioOrder = FrameworkPackageNames . NetFrameworks ;
238
263
239
264
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 ) ;
242
267
243
268
if ( frameworkPath . Path is not null )
244
269
{
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 ) ;
248
271
249
272
for ( var i = frameworkPath . Index + 1 ; i < packagesInPrioOrder . Length ; i ++ )
250
273
{
@@ -308,9 +331,7 @@ private void AddAspNetCoreFrameworkDlls(ISet<string> dllPaths, ISet<string> fram
308
331
// First try to find ASP.NET Core assemblies in the NuGet packages
309
332
if ( GetPackageDirectory ( FrameworkPackageNames . AspNetCoreFramework ) is string aspNetCorePackage )
310
333
{
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 ) ;
314
335
return ;
315
336
}
316
337
@@ -326,9 +347,7 @@ private void AddMicrosoftWindowsDesktopDlls(ISet<string> dllPaths, ISet<string>
326
347
{
327
348
if ( GetPackageDirectory ( FrameworkPackageNames . WindowsDesktopFramework ) is string windowsDesktopApp )
328
349
{
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 ) ;
332
351
}
333
352
}
334
353
0 commit comments