2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
4
using System . Collections . Generic ;
5
+ using System . Diagnostics ;
5
6
using System . IO ;
6
7
using Microsoft . DotNet . ApiCompatibility ;
7
8
using Microsoft . DotNet . ApiCompatibility . Logging ;
@@ -25,21 +26,15 @@ public static void QueueApiCompatFromContentItem(this IApiCompatRunner apiCompat
25
26
Package leftPackage ,
26
27
Package ? rightPackage = null )
27
28
{
29
+ Debug . Assert ( leftContentItems . Count > 0 ) ;
30
+ Debug . Assert ( rightContentItems . Count > 0 ) ;
31
+
28
32
// 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 ) )
30
34
{
31
35
return ;
32
36
}
33
37
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
-
43
38
MetadataInformation [ ] right = new MetadataInformation [ rightContentItems . Count ] ;
44
39
for ( int rightIndex = 0 ; rightIndex < rightContentItems . Count ; rightIndex ++ )
45
40
{
@@ -48,30 +43,46 @@ public static void QueueApiCompatFromContentItem(this IApiCompatRunner apiCompat
48
43
rightContentItems [ rightIndex ] ) ;
49
44
}
50
45
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
+
51
57
apiCompatRunner . EnqueueWorkItem ( new ApiCompatRunnerWorkItem ( left , options , right ) ) ;
52
58
}
53
59
54
60
private static MetadataInformation GetMetadataInformation ( ISuppressableLog log ,
55
61
Package package ,
56
62
ContentItem item ,
57
- string ? displayString = null )
63
+ string ? displayString = null ,
64
+ IEnumerable < string > ? assemblyReferences = null )
58
65
{
59
66
displayString ??= item . Path ;
60
- string [ ] ? assemblyReferences = null ;
61
67
62
68
if ( item . Properties . TryGetValue ( "tfm" , out object ? tfmObj ) )
63
69
{
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 ( ) ;
67
71
68
- if ( package . AssemblyReferences != null && assemblyReferences is null )
72
+ if ( package . AssemblyReferences != null )
69
73
{
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
+ }
75
86
}
76
87
}
77
88
0 commit comments