@@ -2,6 +2,7 @@ namespace GitVersion.Helpers
2
2
{
3
3
using System ;
4
4
using System . Collections . Generic ;
5
+ using System . ComponentModel ;
5
6
using System . Diagnostics ;
6
7
using System . IO ;
7
8
using System . Runtime . InteropServices ;
@@ -20,8 +21,24 @@ public static Process Start(ProcessStartInfo startInfo)
20
21
{
21
22
using ( new ChangeErrorMode ( ErrorModes . FailCriticalErrors | ErrorModes . NoGpFaultErrorBox ) )
22
23
{
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
+ }
25
42
}
26
43
}
27
44
@@ -32,10 +49,12 @@ public static Process Start(ProcessStartInfo startInfo)
32
49
public static int Run ( Action < string > output , Action < string > errorOutput , TextReader input , string exe , string args , string workingDirectory , params KeyValuePair < string , string > [ ] environmentalVariables )
33
50
{
34
51
if ( String . IsNullOrEmpty ( exe ) )
35
- throw new FileNotFoundException ( ) ;
52
+ throw new ArgumentNullException ( "exe" ) ;
36
53
if ( output == null )
37
54
throw new ArgumentNullException ( "output" ) ;
38
55
56
+ workingDirectory = workingDirectory ?? Environment . CurrentDirectory ;
57
+
39
58
var psi = new ProcessStartInfo
40
59
{
41
60
UseShellExecute = false ,
@@ -45,7 +64,7 @@ public static int Run(Action<string> output, Action<string> errorOutput, TextRea
45
64
WindowStyle = ProcessWindowStyle . Hidden ,
46
65
CreateNoWindow = true ,
47
66
ErrorDialog = false ,
48
- WorkingDirectory = workingDirectory ?? Environment . CurrentDirectory ,
67
+ WorkingDirectory = workingDirectory ,
49
68
FileName = exe ,
50
69
Arguments = args
51
70
} ;
@@ -57,7 +76,7 @@ public static int Run(Action<string> output, Action<string> errorOutput, TextRea
57
76
psi . EnvironmentVariables . Remove ( environmentalVariable . Key ) ;
58
77
}
59
78
60
- using ( var process = Process . Start ( psi ) )
79
+ using ( var process = Start ( psi ) )
61
80
using ( var mreOut = new ManualResetEvent ( false ) )
62
81
using ( var mreErr = new ManualResetEvent ( false ) )
63
82
{
@@ -120,5 +139,4 @@ public ChangeErrorMode(ErrorModes mode)
120
139
static extern int SetErrorMode ( int newMode ) ;
121
140
}
122
141
}
123
-
124
142
}
0 commit comments