'Unable to run console application from another project

I have two projects in same solution, the first one is a console app and the second one is a web app. I am trying to run the console application from the server project but it's not working. Here is what I have tries:

        var dllPath = @"path\ConsoleAppName.exe";
        var arguments = "";
        ProcessStartInfo procStartInfo = new ProcessStartInfo();
        procStartInfo.FileName = "dotnet";
        procStartInfo.Arguments = $"dotnet \"{dllPath}\" {arguments}";
        procStartInfo.UseShellExecute = false;
        procStartInfo.CreateNoWindow = false;
        procStartInfo.RedirectStandardOutput = true;
        procStartInfo.RedirectStandardError = true;

        StringBuilder sb = new StringBuilder();
        Process pr = new Process();
        pr.StartInfo = procStartInfo;

        pr.OutputDataReceived += (s, ev) =>
        {
            if (string.IsNullOrWhiteSpace(ev.Data))
            {
                return;
            }
        };

        pr.ErrorDataReceived += (s, err) =>
        {
            // do stuff here
        };

        pr.EnableRaisingEvents = true;
        pr.Start();
        pr.BeginOutputReadLine();
        pr.BeginErrorReadLine();

        pr.WaitForExit();

I have also tried to put @"path\ConsoleAppName.dll" in dllPath but also it didn't work.

Any help?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source