@@ -27,6 +27,7 @@ internal sealed class BuildAnalysis : IDisposable
2727 private int conflictedReferences = 0 ;
2828 private readonly Options options ;
2929 private readonly DirectoryInfo sourceDir ;
30+ private readonly DotNet dotnet ;
3031
3132 /// <summary>
3233 /// Performs a C# build analysis.
@@ -41,6 +42,16 @@ public BuildAnalysis(Options options, ProgressMonitor progressMonitor)
4142 this . progressMonitor = progressMonitor ;
4243 this . sourceDir = new DirectoryInfo ( options . SrcDir ) ;
4344
45+ try
46+ {
47+ this . dotnet = new DotNet ( progressMonitor ) ;
48+ }
49+ catch
50+ {
51+ progressMonitor . MissingDotNet ( ) ;
52+ throw ;
53+ }
54+
4455 this . progressMonitor . FindingFiles ( options . SrcDir ) ;
4556
4657 this . allSources = GetFiles ( "*.cs" ) . ToArray ( ) ;
@@ -82,7 +93,7 @@ public BuildAnalysis(Options options, ProgressMonitor progressMonitor)
8293 // TODO: remove the below when the required SDK is installed
8394 using ( new FileRenamer ( sourceDir . GetFiles ( "global.json" , SearchOption . AllDirectories ) ) )
8495 {
85- RestoreSolutions ( solutions ) ;
96+ Restore ( solutions ) ;
8697 }
8798 }
8899
@@ -304,33 +315,17 @@ private void AnalyseProject(FileInfo project)
304315
305316 }
306317
307- private void Restore ( string projectOrSolution )
318+ private void Restore ( string target )
308319 {
309- int exit ;
310- try
311- {
312- exit = DotNet . RestoreToDirectory ( projectOrSolution , packageDirectory . DirInfo . FullName ) ;
313- }
314- catch ( FileNotFoundException )
315- {
316- exit = 2 ;
317- }
318-
319- switch ( exit )
320- {
321- case 0 :
322- case 1 :
323- // No errors
324- break ;
325- default :
326- progressMonitor . CommandFailed ( "dotnet" , $ "restore \" { projectOrSolution } \" ", exit ) ;
327- break ;
328- }
320+ dotnet . RestoreToDirectory ( target , packageDirectory . DirInfo . FullName ) ;
329321 }
330322
331- private void RestoreSolutions ( IEnumerable < string > solutions )
323+ private void Restore ( IEnumerable < string > targets )
332324 {
333- Parallel . ForEach ( solutions , new ParallelOptions { MaxDegreeOfParallelism = 4 } , Restore ) ;
325+ foreach ( var target in targets )
326+ {
327+ Restore ( target ) ;
328+ }
334329 }
335330
336331 private void AnalyseSolutions ( IEnumerable < string > solutions )
0 commit comments