@@ -34,20 +34,35 @@ private void Info()
3434 }
3535 }
3636
37- private bool RunCommand ( string args )
37+ private static ProcessStartInfo MakeDotnetStartInfo ( string args ) =>
38+ new ProcessStartInfo ( dotnet , args )
39+ {
40+ UseShellExecute = false ,
41+ RedirectStandardOutput = true
42+ } ;
43+
44+ private bool RunCommandAux ( string args , bool silent )
3845 {
3946 progressMonitor . RunningProcess ( $ "{ dotnet } { args } ") ;
40- using var proc = Process . Start ( dotnet , args ) ;
41- proc . WaitForExit ( ) ;
42- if ( proc . ExitCode != 0 )
47+ using var proc = silent
48+ ? Process . Start ( MakeDotnetStartInfo ( args ) )
49+ : Process . Start ( dotnet , args ) ;
50+ proc ? . WaitForExit ( ) ;
51+ var exitCode = proc ? . ExitCode ?? - 1 ;
52+ if ( exitCode != 0 )
4353 {
44- progressMonitor . CommandFailed ( dotnet , args , proc . ExitCode ) ;
54+ progressMonitor . CommandFailed ( dotnet , args , exitCode ) ;
4555 return false ;
4656 }
47-
4857 return true ;
4958 }
5059
60+ private bool RunCommand ( string args ) =>
61+ RunCommandAux ( args , false ) ;
62+
63+ private bool RunCommandSilently ( string args ) =>
64+ RunCommandAux ( args , true ) ;
65+
5166 public bool RestoreToDirectory ( string projectOrSolutionFile , string packageDirectory , string ? pathToNugetConfig = null )
5267 {
5368 var args = $ "restore --no-dependencies \" { projectOrSolutionFile } \" --packages \" { packageDirectory } \" /p:DisableImplicitNuGetFallbackFolder=true";
@@ -75,11 +90,7 @@ public bool AddPackage(string folder, string package)
7590 private IList < string > GetListed ( string args , string artifact )
7691 {
7792 progressMonitor . RunningProcess ( $ "{ dotnet } { args } ") ;
78- var pi = new ProcessStartInfo ( dotnet , args )
79- {
80- RedirectStandardOutput = true ,
81- UseShellExecute = false
82- } ;
93+ var pi = MakeDotnetStartInfo ( args ) ;
8394 var exitCode = pi . ReadOutput ( out var artifacts ) ;
8495 if ( exitCode != 0 )
8596 {
@@ -92,9 +103,8 @@ private IList<string> GetListed(string args, string artifact)
92103
93104 public bool Exec ( string execArgs )
94105 {
95- // TODO: we might need to swallow the stdout of the started process to not pollute the logs of the extraction.
96106 var args = $ "exec { execArgs } ";
97- return RunCommand ( args ) ;
107+ return RunCommandSilently ( args ) ;
98108 }
99109 }
100110}
0 commit comments