@@ -144,11 +144,12 @@ public HashSet<AssemblyLookupLocation> Restore()
144144 logger . LogError ( $ "Failed to restore Nuget packages with nuget.exe: { exc . Message } ") ;
145145 }
146146
147- var restoredProjects = RestoreSolutions ( out var assets1 ) ;
147+ var restoredProjects = RestoreSolutions ( out var container ) ;
148148 var projects = fileProvider . Projects . Except ( restoredProjects ) ;
149- RestoreProjects ( projects , out var assets2 ) ;
149+ RestoreProjects ( projects , out var containers ) ;
150150
151- var dependencies = Assets . GetCompilationDependencies ( logger , assets1 . Union ( assets2 ) ) ;
151+ containers . Add ( container ) ;
152+ var dependencies = containers . Flatten ( ) ;
152153
153154 var paths = dependencies
154155 . Paths
@@ -198,14 +199,14 @@ private List<string> GetReachableFallbackNugetFeeds()
198199 /// As opposed to RestoreProjects this is not run in parallel using PLINQ
199200 /// as `dotnet restore` on a solution already uses multiple threads for restoring
200201 /// the projects (this can be disabled with the `--disable-parallel` flag).
201- /// Populates assets with the relative paths to the assets files generated by the restore.
202+ /// Populates dependencies with the relevant dependencies from the assets files generated by the restore.
202203 /// Returns a list of projects that are up to date with respect to restore.
203204 /// </summary>
204- private IEnumerable < string > RestoreSolutions ( out IEnumerable < string > assets )
205+ private IEnumerable < string > RestoreSolutions ( out DependencyContainer dependencies )
205206 {
206207 var successCount = 0 ;
207208 var nugetSourceFailures = 0 ;
208- var assetFiles = new List < string > ( ) ;
209+ var assets = new Assets ( logger ) ;
209210 var projects = fileProvider . Solutions . SelectMany ( solution =>
210211 {
211212 logger . LogInfo ( $ "Restoring solution { solution } ...") ;
@@ -218,10 +219,10 @@ private IEnumerable<string> RestoreSolutions(out IEnumerable<string> assets)
218219 {
219220 nugetSourceFailures ++ ;
220221 }
221- assetFiles . AddRange ( res . AssetsFilePaths ) ;
222+ assets . AddDependenciesRange ( res . AssetsFilePaths ) ;
222223 return res . RestoredProjects ;
223224 } ) . ToList ( ) ;
224- assets = assetFiles ;
225+ dependencies = assets . Dependencies ;
225226 compilationInfoContainer . CompilationInfos . Add ( ( "Successfully restored solution files" , successCount . ToString ( ) ) ) ;
226227 compilationInfoContainer . CompilationInfos . Add ( ( "Failed solution restore with package source error" , nugetSourceFailures . ToString ( ) ) ) ;
227228 compilationInfoContainer . CompilationInfos . Add ( ( "Restored projects through solution files" , projects . Count . ToString ( ) ) ) ;
@@ -231,22 +232,24 @@ private IEnumerable<string> RestoreSolutions(out IEnumerable<string> assets)
231232 /// <summary>
232233 /// Executes `dotnet restore` on all projects in projects.
233234 /// This is done in parallel for performance reasons.
234- /// Populates assets with the relative paths to the assets files generated by the restore.
235+ /// Populates dependencies with the relative paths to the assets files generated by the restore.
235236 /// </summary>
236237 /// <param name="projects">A list of paths to project files.</param>
237- private void RestoreProjects ( IEnumerable < string > projects , out IEnumerable < string > assets )
238+ private void RestoreProjects ( IEnumerable < string > projects , out List < DependencyContainer > dependencies )
238239 {
239240 var successCount = 0 ;
240241 var nugetSourceFailures = 0 ;
241- var assetFiles = new List < string > ( ) ;
242+ List < DependencyContainer > collectedDependencies = [ ] ;
242243 var sync = new object ( ) ;
243244 var projectGroups = projects . GroupBy ( Path . GetDirectoryName ) ;
244245 Parallel . ForEach ( projectGroups , new ParallelOptions { MaxDegreeOfParallelism = DependencyManager . Threads } , projectGroup =>
245246 {
247+ var assets = new Assets ( logger ) ;
246248 foreach ( var project in projectGroup )
247249 {
248250 logger . LogInfo ( $ "Restoring project { project } ...") ;
249251 var res = dotnet . Restore ( new ( project , PackageDirectory . DirInfo . FullName , ForceDotnetRefAssemblyFetching : true ) ) ;
252+ assets . AddDependenciesRange ( res . AssetsFilePaths ) ;
250253 lock ( sync )
251254 {
252255 if ( res . Success )
@@ -257,11 +260,14 @@ private void RestoreProjects(IEnumerable<string> projects, out IEnumerable<strin
257260 {
258261 nugetSourceFailures ++ ;
259262 }
260- assetFiles . AddRange ( res . AssetsFilePaths ) ;
261263 }
262264 }
265+ lock ( sync )
266+ {
267+ collectedDependencies . Add ( assets . Dependencies ) ;
268+ }
263269 } ) ;
264- assets = assetFiles ;
270+ dependencies = collectedDependencies ;
265271 compilationInfoContainer . CompilationInfos . Add ( ( "Successfully restored project files" , successCount . ToString ( ) ) ) ;
266272 compilationInfoContainer . CompilationInfos . Add ( ( "Failed project restore with package source error" , nugetSourceFailures . ToString ( ) ) ) ;
267273 }
0 commit comments