I get a Win32Exception File not found when trying to run an external executable (with dependencies) from a C# solution with the following code.
public static string TestMethod()
{
    try
    {
        Process p = new Process();
        p.StartInfo.UseShellExecute = false;
        p.StartInfo.RedirectStandardOutput = true;
        p.StartInfo.FileName = Path.Combine("dist", @"test.exe");
        p.Start();
    }
    catch (Exception ex)
    {
        expMessage = ex.Message;
    }
    return expMessage;
}
Remarks:
- No exception occurs when an absolute path is specified as FileName.
- In MS Visual Studio the distsubfolder files properties are set to the following and thedistdirectory is indeed copied into the output folder:- Build action: Content
- Always copy in output directory
 
- I have tried with a test.exe.configfile as follows but with no success:
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <probing privatePath="dist"/>
    </assemblyBinding>
  </runtime>
</configuration>
EDIT  The only solution proposed in Specifying a relative path which actually works in this case is the one eventually provided as a comment by  Viacheslav Smityukh combining AppDomain.CurrentDomain.SetupInformation.ApplicationBase to reconstruct the absolute path. However there seems to be a potential issue at runtime as stated in Pavel Pája Halbich's answer below. From How can I get the application's path in a .NET console application? I found out another solution based on Mr.Mindor's comment using the following code:
string uriPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);
string localPath = new Uri(uriPath).LocalPath;
string testpath = Path.Combine(localPath, "dist", @"test.exe");
Now I wonder which one is the proper way considering a future deployment of the solution with Window Installer.
 
     
    