@@ -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
@@ -37,10 +54,6 @@ public static int Run(Action<string> output, Action<string> errorOutput, TextRea
3754 throw new ArgumentNullException ( "output" ) ;
3855
3956 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 ) ;
4457
4558 var psi = new ProcessStartInfo
4659 {
@@ -63,7 +76,7 @@ public static int Run(Action<string> output, Action<string> errorOutput, TextRea
6376 psi . EnvironmentVariables . Remove ( environmentalVariable . Key ) ;
6477 }
6578
66- using ( var process = Process . Start ( psi ) )
79+ using ( var process = Start ( psi ) )
6780 using ( var mreOut = new ManualResetEvent ( false ) )
6881 using ( var mreErr = new ManualResetEvent ( false ) )
6982 {
@@ -126,5 +139,4 @@ public ChangeErrorMode(ErrorModes mode)
126139 static extern int SetErrorMode ( int newMode ) ;
127140 }
128141 }
129-
130142}
0 commit comments