I have a solution that gets C# sources from a GIT repository and then it should build it into dlls. So I've been trying to build them with dotnet build, but it caused my app to hang.
Found: https://github.com/dotnet/sdk/issues/9487 pointing to --disable-build-servers
, but it does not seem to change anything.
var arguments = $"build '{csproj.FullName}' -o '{target}' --disable-build-servers --no-self-contained";
var process = "dotnet";
var procStart = new ProcessStartInfo(process, arguments.Replace("'", "\""));
procStart.WorkingDirectory = workDir?.FullName ?? new FileInfo(Assembly.GetExecutingAssembly().Location).DirectoryName;
procStart.RedirectStandardOutput = true;
procStart.RedirectStandardError = true;
Logger.LogInformation($"Running: {process} {arguments}");
var proc = new Process();
proc.StartInfo = procStart;
proc.OutputDataReceived += Proc_OutputDataReceived;
proc.ErrorDataReceived += Proc_OutputDataReceived;
proc.Start();
// Here it hangs...
while (!proc.HasExited)
await Task.Delay(100);
if (proc.ExitCode != 0)
{
Logger.LogWarning(proc.StandardOutput.ReadToEnd());
Logger.LogError(proc.StandardError.ReadToEnd());
throw new Exception($"{process} {arguments} exited with exit code: {proc.ExitCode}.");
}
Once I reach this part of the code the Process will never finish, even if I add --disable-build-servers parameter. (I'd have expected that it behaves like running msbuild a while ago.)
Is there a way to run a build out of a C# program that terminates and returns/redirects the command line output as well?