@@ -128,16 +128,27 @@ public DependencyManager(string srcDir, IDependencyOptions options, ILogger logg
128
128
DownloadMissingPackages ( allNonBinaryFiles , dllPaths ) ;
129
129
}
130
130
131
+ var frameworkLocations = new List < 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
+ var path = AddNetFrameworkDlls ( dllPaths ) ;
138
+ frameworkLocations . Add ( path ) ;
139
+ path = AddAspNetCoreFrameworkDlls ( dllPaths ) ;
140
+ if ( path != null )
141
+ {
142
+ frameworkLocations . Add ( path ) ;
143
+ }
144
+ path = AddMicrosoftWindowsDesktopDlls ( dllPaths ) ;
145
+ if ( path != null )
146
+ {
147
+ frameworkLocations . Add ( path ) ;
148
+ }
138
149
}
139
150
140
- assemblyCache = new AssemblyCache ( dllPaths , progressMonitor ) ;
151
+ assemblyCache = new AssemblyCache ( dllPaths , frameworkLocations , progressMonitor ) ;
141
152
AnalyseSolutions ( solutions ) ;
142
153
143
154
foreach ( var filename in assemblyCache . AllAssemblies . Select ( a => a . Filename ) )
@@ -146,7 +157,7 @@ public DependencyManager(string srcDir, IDependencyOptions options, ILogger logg
146
157
}
147
158
148
159
RemoveNugetAnalyzerReferences ( ) ;
149
- ResolveConflicts ( ) ;
160
+ ResolveConflicts ( frameworkLocations ) ;
150
161
151
162
// Output the findings
152
163
foreach ( var r in usedReferences . Keys . OrderBy ( r => r ) )
@@ -228,7 +239,7 @@ private void RemoveNugetAnalyzerReferences()
228
239
}
229
240
}
230
241
231
- private void AddNetFrameworkDlls ( ISet < string > dllPaths )
242
+ private string AddNetFrameworkDlls ( ISet < string > dllPaths )
232
243
{
233
244
// Multiple dotnet framework packages could be present.
234
245
// The order of the packages is important, we're adding the first one that is present in the nuget cache.
@@ -248,7 +259,7 @@ private void AddNetFrameworkDlls(ISet<string> dllPaths)
248
259
RemoveNugetPackageReference ( packagesInPrioOrder [ i ] , dllPaths ) ;
249
260
}
250
261
251
- return ;
262
+ return frameworkPath . Path ;
252
263
}
253
264
254
265
string ? runtimeLocation = null ;
@@ -270,6 +281,7 @@ private void AddNetFrameworkDlls(ISet<string> dllPaths)
270
281
271
282
progressMonitor . LogInfo ( $ ".NET runtime location selected: { runtimeLocation } ") ;
272
283
dllPaths . Add ( runtimeLocation ) ;
284
+ return runtimeLocation ;
273
285
}
274
286
275
287
private void RemoveNugetPackageReference ( string packagePrefix , ISet < string > dllPaths )
@@ -294,33 +306,41 @@ private void RemoveNugetPackageReference(string packagePrefix, ISet<string> dllP
294
306
}
295
307
}
296
308
297
- private void AddAspNetCoreFrameworkDlls ( ISet < string > dllPaths )
309
+ private string ? AddAspNetCoreFrameworkDlls ( ISet < string > dllPaths )
298
310
{
299
311
if ( ! fileContent . IsNewProjectStructureUsed || ! fileContent . UseAspNetCoreDlls )
300
312
{
301
- return ;
313
+ return null ;
302
314
}
303
315
304
316
// First try to find ASP.NET Core assemblies in the NuGet packages
305
317
if ( GetPackageDirectory ( FrameworkPackageNames . AspNetCoreFramework ) is string aspNetCorePackage )
306
318
{
307
319
progressMonitor . LogInfo ( $ "Found ASP.NET Core in NuGet packages. Not adding installation directory.") ;
308
320
dllPaths . Add ( aspNetCorePackage ) ;
321
+ return aspNetCorePackage ;
309
322
}
310
- else if ( Runtime . AspNetCoreRuntime is string aspNetCoreRuntime )
323
+
324
+ if ( Runtime . AspNetCoreRuntime is string aspNetCoreRuntime )
311
325
{
312
326
progressMonitor . LogInfo ( $ "ASP.NET runtime location selected: { aspNetCoreRuntime } ") ;
313
327
dllPaths . Add ( aspNetCoreRuntime ) ;
328
+ return aspNetCoreRuntime ;
314
329
}
330
+
331
+ return null ;
315
332
}
316
333
317
- private void AddMicrosoftWindowsDesktopDlls ( ISet < string > dllPaths )
334
+ private string ? AddMicrosoftWindowsDesktopDlls ( ISet < string > dllPaths )
318
335
{
319
336
if ( GetPackageDirectory ( FrameworkPackageNames . WindowsDesktopFramework ) is string windowsDesktopApp )
320
337
{
321
338
progressMonitor . LogInfo ( $ "Found Windows Desktop App in NuGet packages.") ;
322
339
dllPaths . Add ( windowsDesktopApp ) ;
340
+ return windowsDesktopApp ;
323
341
}
342
+
343
+ return null ;
324
344
}
325
345
326
346
private string ? GetPackageDirectory ( string packagePrefix )
@@ -472,7 +492,7 @@ private string GetTemporaryWorkingDirectory(string subfolder)
472
492
/// If the same assembly name is duplicated with different versions,
473
493
/// resolve to the higher version number.
474
494
/// </summary>
475
- private void ResolveConflicts ( )
495
+ private void ResolveConflicts ( IEnumerable < string > frameworkPaths )
476
496
{
477
497
var sortedReferences = new List < AssemblyInfo > ( ) ;
478
498
foreach ( var usedReference in usedReferences )
@@ -488,11 +508,8 @@ private void ResolveConflicts()
488
508
}
489
509
}
490
510
491
- var emptyVersion = new Version ( 0 , 0 ) ;
492
511
sortedReferences = sortedReferences
493
- . OrderBy ( r => r . NetCoreVersion ?? emptyVersion )
494
- . ThenBy ( r => r . Version ?? emptyVersion )
495
- . ThenBy ( r => r . Filename )
512
+ . OrderAssemblyInfosByPreference ( frameworkPaths )
496
513
. ToList ( ) ;
497
514
498
515
var finalAssemblyList = new Dictionary < string , AssemblyInfo > ( ) ;
0 commit comments