示例#1
0
    private async Task <bool> Build(ProjectInformation example)
    {
        var exitCode = await _console.Status().StartAsync($"Building example [yellow]{example.Name}[/]...", async ctx =>
        {
            var cmd = Cli.Wrap("dotnet").WithArguments("build")
                      .WithWorkingDirectory(example.GetWorkingDirectory().FullPath)
                      .WithValidation(CommandResultValidation.None);

            await foreach (var cmdEvent in cmd.ListenAsync())
            {
                switch (cmdEvent)
                {
                case StandardErrorCommandEvent stdErr:
                    _console.MarkupLine($"[red]ERR>[/] {stdErr.Text.EscapeMarkup()}");
                    break;

                case ExitedCommandEvent exited:
                    return(exited.ExitCode);
                }
            }

            // Should never occur
            return(-1);
        }).ConfigureAwait(false);

        if (exitCode != 0)
        {
            _console.MarkupLine($"[red]Error:[/] Could not build example [u]{example.Name}[/]");
        }

        return(exitCode == 0);
    }