@@ -2,6 +2,7 @@ namespace GitVersion.Helpers
22{
33 using System ;
44 using System . Collections . Generic ;
5+ using System . ComponentModel ;
56 using System . Diagnostics ;
67 using System . IO ;
78 using System . Runtime . InteropServices ;
@@ -20,8 +21,24 @@ public static Process Start(ProcessStartInfo startInfo)
2021 {
2122 using ( new ChangeErrorMode ( ErrorModes . FailCriticalErrors | ErrorModes . NoGpFaultErrorBox ) )
2223 {
23- process = Process . Start ( startInfo ) ;
24- process . PriorityClass = ProcessPriorityClass . Idle ;
24+ try
25+ {
26+ process = Process . Start ( startInfo ) ;
27+ process . PriorityClass = ProcessPriorityClass . Idle ;
28+ }
29+ catch ( Win32Exception exception )
30+ {
31+ // NOTE: https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396 @asbjornu
32+ if ( exception . NativeErrorCode == 2 )
33+ {
34+ throw new FileNotFoundException ( String . Format ( "The executable file '{0}' could not be found." ,
35+ startInfo . FileName ) ,
36+ startInfo . FileName ,
37+ exception ) ;
38+ }
39+
40+ throw ;
41+ }
2542 }
2643 }
2744
@@ -32,10 +49,12 @@ public static Process Start(ProcessStartInfo startInfo)
3249 public static int Run ( Action < string > output , Action < string > errorOutput , TextReader input , string exe , string args , string workingDirectory , params KeyValuePair < string , string > [ ] environmentalVariables )
3350 {
3451 if ( String . IsNullOrEmpty ( exe ) )
35- throw new FileNotFoundException ( ) ;
52+ throw new ArgumentNullException ( "exe" ) ;
3653 if ( output == null )
3754 throw new ArgumentNullException ( "output" ) ;
3855
56+ workingDirectory = workingDirectory ?? Environment . CurrentDirectory ;
57+
3958 var psi = new ProcessStartInfo
4059 {
4160 UseShellExecute = false ,
@@ -45,7 +64,7 @@ public static int Run(Action<string> output, Action<string> errorOutput, TextRea
4564 WindowStyle = ProcessWindowStyle . Hidden ,
4665 CreateNoWindow = true ,
4766 ErrorDialog = false ,
48- WorkingDirectory = workingDirectory ?? Environment . CurrentDirectory ,
67+ WorkingDirectory = workingDirectory ,
4968 FileName = exe ,
5069 Arguments = args
5170 } ;
@@ -57,7 +76,7 @@ public static int Run(Action<string> output, Action<string> errorOutput, TextRea
5776 psi . EnvironmentVariables . Remove ( environmentalVariable . Key ) ;
5877 }
5978
60- using ( var process = Process . Start ( psi ) )
79+ using ( var process = Start ( psi ) )
6180 using ( var mreOut = new ManualResetEvent ( false ) )
6281 using ( var mreErr = new ManualResetEvent ( false ) )
6382 {
@@ -120,5 +139,4 @@ public ChangeErrorMode(ErrorModes mode)
120139 static extern int SetErrorMode ( int newMode ) ;
121140 }
122141 }
123-
124142}
0 commit comments