Skip to content
This repository has been archived by the owner on Nov 20, 2023. It is now read-only.

Commit

Permalink
Log from stdout when dotnet publish fails (#456)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkotalik authored May 7, 2020
1 parent 7395203 commit c7a2b30
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/Microsoft.Tye.Core/PublishProjectStep.cs
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.CommandLine.Invocation;
using System.IO;
using System.Threading.Tasks;
@@ -36,18 +37,29 @@ public override async Task ExecuteAsync(OutputContext output, ApplicationBuilder

output.WriteDebugLine("Running 'dotnet publish'.");
output.WriteCommandLine("dotnet", $"publish \"{project.ProjectFile.FullName}\" -c Release -o \"{outputDirectory.DirectoryPath}\"");
var capture = output.Capture();
var exitCode = await Process.ExecuteAsync(

var publishResult = await ProcessUtil.RunAsync(
$"dotnet",
$"publish \"{project.ProjectFile.FullName}\" -c Release -o \"{outputDirectory.DirectoryPath}\"",
project.ProjectFile.DirectoryName,
stdOut: capture.StdOut,
stdErr: capture.StdErr);
throwOnError: false);

output.WriteDebugLine($"Done running 'dotnet publish' exit code: {exitCode}");
if (exitCode != 0)
output.WriteDebugLine($"Done running 'dotnet publish' exit code: {publishResult.ExitCode}");
if (publishResult.ExitCode != 0)
{
outputDirectory.Dispose();
output.WriteInfoLine($"'dotnet publish' failed. Error:");

foreach (var line in publishResult.StandardOutput.Split(Environment.NewLine))
{
output.WriteInfoLine(line);
}

foreach (var line in publishResult.StandardError.Split(Environment.NewLine))
{
output.WriteInfoLine(line);
}

throw new CommandException("'dotnet publish' failed.");
}

0 comments on commit c7a2b30

Please sign in to comment.