@@ -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
@@ -37,10 +54,6 @@ public static int Run(Action<string> output, Action<string> errorOutput, TextRea
37
54
throw new ArgumentNullException ( "output" ) ;
38
55
39
56
workingDirectory = workingDirectory ?? Environment . CurrentDirectory ;
40
- var exePath = Path . Combine ( workingDirectory , exe ) ;
41
-
42
- if ( ! File . Exists ( exePath ) )
43
- throw new FileNotFoundException ( String . Format ( "The executable file '{0}' does not exist." , exePath ) , exePath ) ;
44
57
45
58
var psi = new ProcessStartInfo
46
59
{
@@ -63,7 +76,7 @@ public static int Run(Action<string> output, Action<string> errorOutput, TextRea
63
76
psi . EnvironmentVariables . Remove ( environmentalVariable . Key ) ;
64
77
}
65
78
66
- using ( var process = Process . Start ( psi ) )
79
+ using ( var process = Start ( psi ) )
67
80
using ( var mreOut = new ManualResetEvent ( false ) )
68
81
using ( var mreErr = new ManualResetEvent ( false ) )
69
82
{
@@ -126,5 +139,4 @@ public ChangeErrorMode(ErrorModes mode)
126
139
static extern int SetErrorMode ( int newMode ) ;
127
140
}
128
141
}
129
-
130
142
}
0 commit comments