Skip to content

Please stop lying about the exit code of an exec task #11821

Description

@softworkz

Summary

When the Exec/ToolTask runs a process with exit code 0 but it has logged to stderr, the task's exit code is set to -1:

// If the tool exited cleanly, but logged errors then assign a failing exit code (-1)
if (ExitCode == 0 && HasLoggedErrors)
{
ExitCode = -1;
}

It's documented and fine (at least when you have read it) and this surely makes some sense.

But when this happens a message is logged like:

The command "xxxxxxx" exited with code -1.

And this is not OK. It is a blatant lie, because the command HAS NOT exited with code -1.

It has exited with code 0 - and only the task's ExitCode property is set to -1 because some output has been logged to stderr.

Background and Motivation

Two painful days totally wasted due to the incorrect log message and I'm pretty sure I'm not the first one.

Proposed Feature

This is not about changing any behavior.

But please fix the log output to make it clear what has happened instead of printing wrong statements.

Thank you
sw

Activity

  1. MichalPavlik commented on May 13, 2025

    @MichalPavlik
    Member

    Triage: we should change the log message to stop lying :)

  2. added
    help wantedIssues that the core team doesn't plan to work on, but would accept a PR for. Comment to claim.
    and removed
    help wantedIssues that the core team doesn't plan to work on, but would accept a PR for. Comment to claim.
    on May 13, 2025
  3. KalleOlaviNiemitalo commented on May 21, 2025

    @KalleOlaviNiemitalo

    The ToolTask.ExitCode property, and the corresponding task parameter, are documented as returning -1 if the process had 0 as the exit code but the task logged some errors. If you change the log output not to claim that the exit code is -1 in this case, and that change affects ToolTask.ExitCode too, please update its documentation. But I hope that the logging change can be made without affecting ToolTask.ExitCode.

    https://github.com/MicrosoftDocs/visualstudio-docs/blob/f7e31b559b822491ab0dc8a2bb1d3d096ad7358c/docs/msbuild/includes/tooltaskextension-base-params.md?plain=1#L17

    https://learn.microsoft.com/dotnet/api/microsoft.build.utilities.tooltask.exitcode

    /// <summary>
    /// The return code of the spawned process. If the task logged any errors, but the process
    /// had an exit code of 0 (success), this will be set to -1.
    /// </summary>
    [Output]
    public int ExitCode { get; private set; }

  4. softworkz commented on May 21, 2025

    @softworkz
    Author

    Changing the ExitCode behavior would be fatal I think.

    The change I'm suggesting is only about the log text, to something like:

    "The command "xxxxxxx" exited with return value 0. Setting task ExitCode to -1 due to log output to STDERR."

    (only in that specific case of course).

  5. self-assigned this
    on Feb 23, 2026
  6. OvesN commented on Mar 2, 2026

    @OvesN
    Contributor

    Resolved with this PR: #13303.
    We now use a more descriptive message in this case.

  7. softworkz commented on Mar 2, 2026

    @softworkz
    Author

    Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions