22// The .NET Foundation licenses this file to you under the MIT license.
33
44using System . Collections . Generic ;
5+ using System . Diagnostics ;
56using System . IO ;
67using Microsoft . DotNet . ApiCompatibility ;
78using Microsoft . DotNet . ApiCompatibility . Logging ;
@@ -25,21 +26,15 @@ public static void QueueApiCompatFromContentItem(this IApiCompatRunner apiCompat
2526 Package leftPackage ,
2627 Package ? rightPackage = null )
2728 {
29+ Debug . Assert ( leftContentItems . Count > 0 ) ;
30+ Debug . Assert ( rightContentItems . Count > 0 ) ;
31+
2832 // Don't enqueue duplicate items (if no right package is supplied and items match)
29- if ( rightPackage == null && ContentItemCollectionEquals ( leftContentItems , rightContentItems ) )
33+ if ( rightPackage is null && ContentItemCollectionEquals ( leftContentItems , rightContentItems ) )
3034 {
3135 return ;
3236 }
3337
34- MetadataInformation [ ] left = new MetadataInformation [ leftContentItems . Count ] ;
35- for ( int leftIndex = 0 ; leftIndex < leftContentItems . Count ; leftIndex ++ )
36- {
37- left [ leftIndex ] = GetMetadataInformation ( log ,
38- leftPackage ,
39- leftContentItems [ leftIndex ] ,
40- options . IsBaselineComparison ? Resources . Baseline + " " + leftContentItems [ leftIndex ] . Path : null ) ;
41- }
42-
4338 MetadataInformation [ ] right = new MetadataInformation [ rightContentItems . Count ] ;
4439 for ( int rightIndex = 0 ; rightIndex < rightContentItems . Count ; rightIndex ++ )
4540 {
@@ -48,30 +43,46 @@ public static void QueueApiCompatFromContentItem(this IApiCompatRunner apiCompat
4843 rightContentItems [ rightIndex ] ) ;
4944 }
5045
46+ MetadataInformation [ ] left = new MetadataInformation [ leftContentItems . Count ] ;
47+ for ( int leftIndex = 0 ; leftIndex < leftContentItems . Count ; leftIndex ++ )
48+ {
49+ left [ leftIndex ] = GetMetadataInformation ( log ,
50+ leftPackage ,
51+ leftContentItems [ leftIndex ] ,
52+ displayString : options . IsBaselineComparison ? Resources . Baseline + " " + leftContentItems [ leftIndex ] . Path : null ,
53+ // Use the assembly references from the right package if the left package doesn't provide them.
54+ assemblyReferences : rightPackage is not null ? right [ right . Length > leftIndex ? leftIndex : 0 ] . References : null ) ;
55+ }
56+
5157 apiCompatRunner . EnqueueWorkItem ( new ApiCompatRunnerWorkItem ( left , options , right ) ) ;
5258 }
5359
5460 private static MetadataInformation GetMetadataInformation ( ISuppressableLog log ,
5561 Package package ,
5662 ContentItem item ,
57- string ? displayString = null )
63+ string ? displayString = null ,
64+ IEnumerable < string > ? assemblyReferences = null )
5865 {
5966 displayString ??= item . Path ;
60- string [ ] ? assemblyReferences = null ;
6167
6268 if ( item . Properties . TryGetValue ( "tfm" , out object ? tfmObj ) )
6369 {
64- // Find the nearest set of assembly references for the package item (assembly).
65- NuGetFramework targetFramework = ( ( NuGetFramework ) tfmObj ) ;
66- assemblyReferences = package . FindBestAssemblyReferencesForFramework ( targetFramework ) ;
70+ string targetFramework = ( ( NuGetFramework ) tfmObj ) . GetShortFolderName ( ) ;
6771
68- if ( package . AssemblyReferences != null && assemblyReferences is null )
72+ if ( package . AssemblyReferences != null )
6973 {
70- log . LogWarning ( new Suppression ( DiagnosticIds . SearchDirectoriesNotFoundForTfm ) { Target = displayString } ,
71- DiagnosticIds . SearchDirectoriesNotFoundForTfm ,
72- string . Format ( Resources . MissingSearchDirectory ,
73- targetFramework . GetShortFolderName ( ) ,
74- displayString ) ) ;
74+ if ( package . AssemblyReferences . TryGetValue ( targetFramework , out string [ ] ? assemblyReferencesRaw ) )
75+ {
76+ assemblyReferences = assemblyReferencesRaw ;
77+ }
78+ else
79+ {
80+ log . LogWarning ( new Suppression ( DiagnosticIds . SearchDirectoriesNotFoundForTfm ) { Target = displayString } ,
81+ DiagnosticIds . SearchDirectoriesNotFoundForTfm ,
82+ string . Format ( Resources . MissingSearchDirectory ,
83+ targetFramework ,
84+ displayString ) ) ;
85+ }
7586 }
7687 }
7788
0 commit comments