@@ -314,21 +314,11 @@ public DependencyContext Build(string[] userRuntimeAssemblies = null)
314
314
* libraryCandidatesForRemoval if it isn't already there
315
315
* Repeat 3 until libraryCandidatesForRemoval is empty
316
316
*/
317
- var libraries = runtimeLibraries . ToDictionary ( lib => lib . Library . Name , lib => lib ) ;
318
- foreach ( var reference in runtimeLibraries )
319
- {
320
- foreach ( var dependency in reference . Library . Dependencies )
321
- {
322
- if ( libraries . TryGetValue ( dependency . Name , out var dep ) )
323
- {
324
- dep . Dependents . Add ( reference . Library . Name ) ;
325
- }
326
- }
327
- }
328
317
329
318
// Rather than adding the main project's dependencies, we added references to them, i.e., Foo.Reference.dll
330
319
// instead of Foo.dll. This adds Foo.dll as a reference directly so another reference can be removed if it
331
320
// isn't necessary because of a direct reference from the main project.
321
+ var referenceNameToRealName = new Dictionary < string , string > ( ) ;
332
322
if ( _includeMainProjectInDepsFile )
333
323
{
334
324
var mainProjectReferences = _directReferences ;
@@ -348,10 +338,20 @@ public DependencyContext Build(string[] userRuntimeAssemblies = null)
348
338
{
349
339
foreach ( var directReference in mainProjectReferences )
350
340
{
351
- if ( libraries . TryGetValue ( directReference . Name , out var dep ) )
352
- {
353
- dep . Dependents . Add ( _mainProjectInfo . Name ) ;
354
- }
341
+ referenceNameToRealName [ GetReferenceLibraryName ( directReference ) ] = directReference . Name ;
342
+ }
343
+ }
344
+ }
345
+
346
+ var libraries = runtimeLibraries . ToDictionary ( lib => lib . Library . Name , lib => lib ) ;
347
+ foreach ( var reference in runtimeLibraries )
348
+ {
349
+ foreach ( var dependency in reference . Library . Dependencies )
350
+ {
351
+ var name = referenceNameToRealName . TryGetValue ( dependency . Name , out var realName ) ? realName : dependency . Name ;
352
+ if ( libraries . TryGetValue ( name , out var dep ) )
353
+ {
354
+ dep . Dependents . Add ( reference . Library . Name ) ;
355
355
}
356
356
}
357
357
}
@@ -370,7 +370,7 @@ public DependencyContext Build(string[] userRuntimeAssemblies = null)
370
370
libraries . Remove ( lib . Library . Name ) ;
371
371
foreach ( var dependency in lib . Library . Dependencies )
372
372
{
373
- if ( libraries . TryGetValue ( dependency . Name , out ModifiableRuntimeLibrary ? value ) )
373
+ if ( libraries . TryGetValue ( dependency . Name , out ModifiableRuntimeLibrary value ) )
374
374
{
375
375
value . Dependents . Remove ( lib . Library . Name ) ;
376
376
}
@@ -479,6 +479,8 @@ public DependencyContext Build(string[] userRuntimeAssemblies = null)
479
479
. Where ( expansion => expansion . Contains ( _runtimeIdentifier ) )
480
480
. Select ( expansion => new RuntimeFallbacks ( expansion . First ( ) , expansion . Skip ( 1 ) ) ) ; // ExpandRuntime return runtime itself as first item.
481
481
482
+ var libraryNames = runtimeLibraries . Select ( lib => lib . Library . Name ) . Concat ( compilationLibraries . Select ( lib => lib . Name ) ) . ToHashSet ( ) ;
483
+
482
484
return new DependencyContext (
483
485
targetInfo ,
484
486
_compilationOptions ?? CompilationOptions . Default ,
@@ -491,9 +493,7 @@ public DependencyContext Build(string[] userRuntimeAssemblies = null)
491
493
library . Library . RuntimeAssemblyGroups ,
492
494
library . Library . NativeLibraryGroups ,
493
495
library . Library . ResourceAssemblies ,
494
- library . Library . Dependencies . Where (
495
- dependency => runtimeLibraries . Any ( lib => lib . Library . Name . Equals ( dependency . Name ) ) ||
496
- compilationLibraries . Any ( lib => lib . Name . Equals ( dependency . Name ) ) ) . ToList ( ) ,
496
+ library . Library . Dependencies . Where ( dependency => libraryNames . Contains ( dependency . Name ) ) . ToList ( ) ,
497
497
library . Library . Serviceable ,
498
498
library . Library . Path ,
499
499
library . Library . HashPath ,
0 commit comments