diff --git a/build.cake b/build.cake index 32746aa6..549ec54d 100644 --- a/build.cake +++ b/build.cake @@ -220,14 +220,17 @@ Task("BuildTest") { var project = pair.Key; var projectFolder = System.IO.Path.Combine(testFolder, project); - var runLog = new List(); - Run(dotnetcli, $"build --framework {framework} --configuration {testConfiguration} \"{projectFolder}\"", + var logPath = System.IO.Path.Combine(logFolder, $"{project}-{framework}-build.log"); + using (var logWriter = new StreamWriter(logPath)) { + Run(dotnetcli, $"build --framework {framework} --configuration {testConfiguration} \"{projectFolder}\"", new RunOptions { - StandardOutputListing = runLog + StandardOutputWriter = logWriter, + StandardErrorWriter = logWriter }) .ExceptionOnError($"Building test {project} failed for {framework}."); - System.IO.File.WriteAllLines(System.IO.Path.Combine(logFolder, $"{project}-{framework}-build.log"), runLog.ToArray()); + } + } } }); diff --git a/scripts/runhelpers.cake b/scripts/runhelpers.cake index b6a194d6..37682fc8 100644 --- a/scripts/runhelpers.cake +++ b/scripts/runhelpers.cake @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Diagnostics; +using System.IO; /// /// Class encompassing the optional settings for running processes. @@ -11,13 +12,13 @@ public class RunOptions /// public string WorkingDirectory { get; set; } /// - /// Container logging the StandardOutput content. + /// Stream to log std out messages to /// - public IList StandardOutputListing { get; set; } + public StreamWriter StandardOutputWriter { get; set; } /// - /// Container logging the Error content. + /// Stream to log std err messages to /// - public IList StandardErrorListing { get; set; } + public StreamWriter StandardErrorWriter { get; set; } /// /// Desired maximum time-out for the process /// @@ -121,27 +122,27 @@ ExitStatus Run(string exec, string args, RunOptions runOptions) { WorkingDirectory = workingDirectory, UseShellExecute = false, - RedirectStandardOutput = runOptions.StandardOutputListing != null, - RedirectStandardError = runOptions.StandardErrorListing != null, + RedirectStandardOutput = runOptions.StandardOutputWriter != null, + RedirectStandardError = runOptions.StandardErrorWriter != null, }); - if (runOptions.StandardOutputListing != null) + if (runOptions.StandardOutputWriter != null) { process.OutputDataReceived += (s, e) => { if (e.Data != null) { - runOptions.StandardOutputListing.Add(e.Data); + runOptions.StandardOutputWriter.WriteLine(e.Data); } }; process.BeginOutputReadLine(); } - if (runOptions.StandardErrorListing != null) + if (runOptions.StandardErrorWriter != null) { process.ErrorDataReceived += (s, e) => { if (e.Data != null) { - runOptions.StandardErrorListing.Add(e.Data); + runOptions.StandardErrorWriter.WriteLine(e.Data); } }; process.BeginErrorReadLine(); @@ -220,21 +221,16 @@ public void KillProcessTree(Process process) } public void DotnetPack(string outputFolder, string projectFolder, string project) { - var runLog = new List(); - var errorLog = new List(); var logPath = System.IO.Path.Combine(logFolder, $"{project}-pack.log"); - Information($"Packaging {projectFolder}"); - try { + using (var logWriter = new StreamWriter(logPath)) { + Information($"Packaging {projectFolder}"); Run(dotnetcli, $"pack --configuration {configuration} --output {outputFolder} \"{projectFolder}\"", new RunOptions { - StandardOutputListing = runLog, - StandardErrorListing = errorLog + StandardOutputWriter = logWriter, + StandardErrorWriter = logWriter }) .ExceptionOnError($"Packaging {project} failed. See {logPath} for details."); - } catch(Exception) { - System.IO.File.WriteAllLines(logPath, runLog.ToArray()); - throw; } - System.IO.File.WriteAllLines(logPath, runLog.ToArray()); + }