@@ -128,16 +128,18 @@ public DependencyManager(string srcDir, IDependencyOptions options, ILogger logg
128
128
DownloadMissingPackages ( allNonBinaryFiles , dllPaths ) ;
129
129
}
130
130
131
+ var frameworkLocations = new HashSet < string > ( ) ;
132
+
131
133
// Find DLLs in the .Net / Asp.Net Framework
132
134
// This block needs to come after the nuget restore, because the nuget restore might fetch the .NET Core/Framework reference assemblies.
133
135
if ( options . ScanNetFrameworkDlls )
134
136
{
135
- AddNetFrameworkDlls ( dllPaths ) ;
136
- AddAspNetCoreFrameworkDlls ( dllPaths ) ;
137
- AddMicrosoftWindowsDesktopDlls ( dllPaths ) ;
137
+ AddNetFrameworkDlls ( dllPaths , frameworkLocations ) ;
138
+ AddAspNetCoreFrameworkDlls ( dllPaths , frameworkLocations ) ;
139
+ AddMicrosoftWindowsDesktopDlls ( dllPaths , frameworkLocations ) ;
138
140
}
139
141
140
- assemblyCache = new AssemblyCache ( dllPaths , progressMonitor ) ;
142
+ assemblyCache = new AssemblyCache ( dllPaths , frameworkLocations , progressMonitor ) ;
141
143
AnalyseSolutions ( solutions ) ;
142
144
143
145
foreach ( var filename in assemblyCache . AllAssemblies . Select ( a => a . Filename ) )
@@ -146,7 +148,7 @@ public DependencyManager(string srcDir, IDependencyOptions options, ILogger logg
146
148
}
147
149
148
150
RemoveNugetAnalyzerReferences ( ) ;
149
- ResolveConflicts ( ) ;
151
+ ResolveConflicts ( frameworkLocations ) ;
150
152
151
153
// Output the findings
152
154
foreach ( var r in usedReferences . Keys . OrderBy ( r => r ) )
@@ -228,7 +230,7 @@ private void RemoveNugetAnalyzerReferences()
228
230
}
229
231
}
230
232
231
- private void AddNetFrameworkDlls ( ISet < string > dllPaths )
233
+ private void AddNetFrameworkDlls ( ISet < string > dllPaths , ISet < string > frameworkLocations )
232
234
{
233
235
// Multiple dotnet framework packages could be present.
234
236
// The order of the packages is important, we're adding the first one that is present in the nuget cache.
@@ -241,6 +243,7 @@ private void AddNetFrameworkDlls(ISet<string> dllPaths)
241
243
if ( frameworkPath . Path is not null )
242
244
{
243
245
dllPaths . Add ( frameworkPath . Path ) ;
246
+ frameworkLocations . Add ( frameworkPath . Path ) ;
244
247
progressMonitor . LogInfo ( $ "Found .NET Core/Framework DLLs in NuGet packages at { frameworkPath . Path } . Not adding installation directory.") ;
245
248
246
249
for ( var i = frameworkPath . Index + 1 ; i < packagesInPrioOrder . Length ; i ++ )
@@ -270,6 +273,7 @@ private void AddNetFrameworkDlls(ISet<string> dllPaths)
270
273
271
274
progressMonitor . LogInfo ( $ ".NET runtime location selected: { runtimeLocation } ") ;
272
275
dllPaths . Add ( runtimeLocation ) ;
276
+ frameworkLocations . Add ( runtimeLocation ) ;
273
277
}
274
278
275
279
private void RemoveNugetPackageReference ( string packagePrefix , ISet < string > dllPaths )
@@ -294,7 +298,7 @@ private void RemoveNugetPackageReference(string packagePrefix, ISet<string> dllP
294
298
}
295
299
}
296
300
297
- private void AddAspNetCoreFrameworkDlls ( ISet < string > dllPaths )
301
+ private void AddAspNetCoreFrameworkDlls ( ISet < string > dllPaths , ISet < string > frameworkLocations )
298
302
{
299
303
if ( ! fileContent . IsNewProjectStructureUsed || ! fileContent . UseAspNetCoreDlls )
300
304
{
@@ -306,20 +310,25 @@ private void AddAspNetCoreFrameworkDlls(ISet<string> dllPaths)
306
310
{
307
311
progressMonitor . LogInfo ( $ "Found ASP.NET Core in NuGet packages. Not adding installation directory.") ;
308
312
dllPaths . Add ( aspNetCorePackage ) ;
313
+ frameworkLocations . Add ( aspNetCorePackage ) ;
314
+ return ;
309
315
}
310
- else if ( Runtime . AspNetCoreRuntime is string aspNetCoreRuntime )
316
+
317
+ if ( Runtime . AspNetCoreRuntime is string aspNetCoreRuntime )
311
318
{
312
319
progressMonitor . LogInfo ( $ "ASP.NET runtime location selected: { aspNetCoreRuntime } ") ;
313
320
dllPaths . Add ( aspNetCoreRuntime ) ;
321
+ frameworkLocations . Add ( aspNetCoreRuntime ) ;
314
322
}
315
323
}
316
324
317
- private void AddMicrosoftWindowsDesktopDlls ( ISet < string > dllPaths )
325
+ private void AddMicrosoftWindowsDesktopDlls ( ISet < string > dllPaths , ISet < string > frameworkLocations )
318
326
{
319
327
if ( GetPackageDirectory ( FrameworkPackageNames . WindowsDesktopFramework ) is string windowsDesktopApp )
320
328
{
321
329
progressMonitor . LogInfo ( $ "Found Windows Desktop App in NuGet packages.") ;
322
330
dllPaths . Add ( windowsDesktopApp ) ;
331
+ frameworkLocations . Add ( windowsDesktopApp ) ;
323
332
}
324
333
}
325
334
@@ -472,7 +481,7 @@ private string GetTemporaryWorkingDirectory(string subfolder)
472
481
/// If the same assembly name is duplicated with different versions,
473
482
/// resolve to the higher version number.
474
483
/// </summary>
475
- private void ResolveConflicts ( )
484
+ private void ResolveConflicts ( IEnumerable < string > frameworkPaths )
476
485
{
477
486
var sortedReferences = new List < AssemblyInfo > ( ) ;
478
487
foreach ( var usedReference in usedReferences )
@@ -488,11 +497,8 @@ private void ResolveConflicts()
488
497
}
489
498
}
490
499
491
- var emptyVersion = new Version ( 0 , 0 ) ;
492
500
sortedReferences = sortedReferences
493
- . OrderBy ( r => r . NetCoreVersion ?? emptyVersion )
494
- . ThenBy ( r => r . Version ?? emptyVersion )
495
- . ThenBy ( r => r . Filename )
501
+ . OrderAssemblyInfosByPreference ( frameworkPaths )
496
502
. ToList ( ) ;
497
503
498
504
var finalAssemblyList = new Dictionary < string , AssemblyInfo > ( ) ;
0 commit comments