@@ -58,7 +58,7 @@ public NuGetMSBuildBinaryLogComponentDetector(
58
58
59
59
public override int Version { get ; } = 1 ;
60
60
61
- private static void ProcessResolvedPackageReference ( Dictionary < string , HashSet < string > > topLevelDependencies , Dictionary < string , Dictionary < string , string > > projectResolvedDependencies , NamedNode node )
61
+ private static void ProcessResolvedPackageReference ( Dictionary < string , HashSet < string > > topLevelDependencies , Dictionary < string , Dictionary < string , HashSet < string > > > projectResolvedDependencies , NamedNode node )
62
62
{
63
63
var doRemoveOperation = node is RemoveItem ;
64
64
var doAddOperation = node is AddItem ;
@@ -110,14 +110,20 @@ private static void ProcessResolvedPackageReference(Dictionary<string, HashSet<s
110
110
projectResolvedDependencies [ project . ProjectFile ] = projectDependencies ;
111
111
}
112
112
113
+ if ( ! projectDependencies . TryGetValue ( packageName , out var packageVersions ) )
114
+ {
115
+ packageVersions = new ( StringComparer . OrdinalIgnoreCase ) ;
116
+ projectDependencies [ packageName ] = packageVersions ;
117
+ }
118
+
113
119
if ( doRemoveOperation )
114
120
{
115
- projectDependencies . Remove ( packageName ) ;
121
+ packageVersions . Remove ( packageVersion ) ;
116
122
}
117
123
118
124
if ( doAddOperation )
119
125
{
120
- projectDependencies [ packageName ] = packageVersion ;
126
+ packageVersions . Add ( packageVersion ) ;
121
127
}
122
128
123
129
project = project . GetNearestParent < Project > ( ) ;
@@ -183,7 +189,7 @@ private void ProcessBinLog(Build buildRoot, ISingleFileComponentRecorder compone
183
189
{
184
190
// maps a project path to a set of resolved dependencies
185
191
var projectTopLevelDependencies = new Dictionary < string , HashSet < string > > ( StringComparer . OrdinalIgnoreCase ) ;
186
- var projectResolvedDependencies = new Dictionary < string , Dictionary < string , string > > ( StringComparer . OrdinalIgnoreCase ) ;
192
+ var projectResolvedDependencies = new Dictionary < string , Dictionary < string , HashSet < string > > > ( StringComparer . OrdinalIgnoreCase ) ;
187
193
buildRoot . VisitAllChildren < BaseNode > ( node =>
188
194
{
189
195
switch ( node )
@@ -198,7 +204,7 @@ private void ProcessBinLog(Build buildRoot, ISingleFileComponentRecorder compone
198
204
199
205
// dependencies were resolved per project, we need to re-arrange them to be per package/version
200
206
var projectsPerPackage = new Dictionary < string , HashSet < string > > ( StringComparer . OrdinalIgnoreCase ) ;
201
- foreach ( var projectPath in projectResolvedDependencies . Keys )
207
+ foreach ( var projectPath in projectResolvedDependencies . Keys . OrderBy ( p => p ) )
202
208
{
203
209
if ( Path . GetExtension ( projectPath ) . Equals ( ".sln" , StringComparison . OrdinalIgnoreCase ) )
204
210
{
@@ -207,16 +213,19 @@ private void ProcessBinLog(Build buildRoot, ISingleFileComponentRecorder compone
207
213
}
208
214
209
215
var projectDependencies = projectResolvedDependencies [ projectPath ] ;
210
- foreach ( var ( packageName , packageVersion ) in projectDependencies )
216
+ foreach ( var ( packageName , packageVersions ) in projectDependencies . OrderBy ( p => p . Key ) )
211
217
{
212
- var key = $ "{ packageName } /{ packageVersion } ";
213
- if ( ! projectsPerPackage . TryGetValue ( key , out var projectPaths ) )
218
+ foreach ( var packageVersion in packageVersions . OrderBy ( v => v ) )
214
219
{
215
- projectPaths = new HashSet < string > ( StringComparer . OrdinalIgnoreCase ) ;
216
- projectsPerPackage [ key ] = projectPaths ;
217
- }
220
+ var key = $ "{ packageName } /{ packageVersion } ";
221
+ if ( ! projectsPerPackage . TryGetValue ( key , out var projectPaths ) )
222
+ {
223
+ projectPaths = new HashSet < string > ( StringComparer . OrdinalIgnoreCase ) ;
224
+ projectsPerPackage [ key ] = projectPaths ;
225
+ }
218
226
219
- projectPaths . Add ( projectPath ) ;
227
+ projectPaths . Add ( projectPath ) ;
228
+ }
220
229
}
221
230
}
222
231
0 commit comments