Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8034205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:56:12+00:00 2026-06-05T01:56:12+00:00

I am running the MSBuild task with ContinueOnError =true : <MSBuild Projects=@(ComponentToDeploy) Targets=$(DeploymentTargets) Properties=$(CommonProperties);%(AdditionalProperties)

  • 0

I am running the MSBuild task with ContinueOnError=true:

<MSBuild Projects="@(ComponentToDeploy)"
    Targets="$(DeploymentTargets)"
    Properties="$(CommonProperties);%(AdditionalProperties)"
    ContinueOnError="true" 
    Condition="%(Condition)"/>

So my build always succeeds.

Is there a way to find out if any error occurs?

I could not find any Output of the MSBuild task containing this information.
The only way I know is to parse the log file for errors but it looks like a workaround for me.

(I am using MSBuild 4.0)


This is an answer to the last feedback of @Ilya.
I’m using feedback/answer because of the length and formatting restrictions of the comments.

Log is scoped to individual targets or to be more specific tasks…

This was indeed the first question arose when I was reading your comment with the suggestion to use Log.HasLoggedErrors: “Was is the scope of the Log?“.
Unfortunately I was not be able to finde a proper documentation. MSND does not help much…
Why did you know it is scoped to the task?
I’m not in doubt about your statement at all! I’m just wondering if there is a proper documentation somewhere..
(I haven’t been using MSBuild for years 😉

In any case, what are you building as project?

My test projects are very simple.
MyTest.project

<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="ElenasTarget" ToolsVersion="4.0">

    <UsingTask AssemblyFile="$(MSBuildProjectDirectory)\MyCompany.Tools.MSBuild.Tasks.dll" TaskName="MSBuildWithHasLoggedErrors" />

    <ItemGroup>
        <MyProjects Include="CopyNotExistingFile.proj" />
    </ItemGroup>

    <Target Name="ElenasTarget">
        <MSBuildWithHasLoggedErrors Projects="@(MyProjects)" ContinueOnError="true" >
            <Output TaskParameter="HasLoggedErrors" PropertyName="BuildFailed" />
         </MSBuildWithHasLoggedErrors>

         <Message Text="BuildFailed=$(BuildFailed)" />
  </Target>
</Project>

The CopyNotExistingFile.proj just tries to copy a file that does not exist:

<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Target1" ToolsVersion="4.0">
    <Target Name="Target1"> 
         <Copy SourceFiles="C:\lalala.bum" DestinationFiles="C:\tralala.bam" />
  </Target>
</Project>

And this is my custom task MSBuildWithHasLoggedErrors

namespace MyCompany.Tools.MSBuild.Tasks
{
    public class MSBuildWithHasLoggedErrors : Microsoft.Build.Tasks.MSBuild
    {
        [Output]
        public bool HasLoggedErrors { get; private set; }

        public override bool Execute()
        {
            try
            {
                base.Execute();
                HasLoggedErrors = Log.HasLoggedErrors;
            }
            catch (Exception e)
            {
                Log.LogErrorFromException(e, true);
                return false;
            }

            return true;
        }
    }
}

If I build my MyTest.proj the HasLoggedErrorswill be set to false although an error (MSB3021) was logged(?) to the console logger:

Project "C:\Users\elena\mytest.proj" on node 1 (default targets).
Project "C:\Users\elena\mytest.proj" (1) is building "C:\Users\elena\CopyNotExistingFile.proj" (2) on node 1 (default targets).
Target1:
  Copying file from "C:\lalala.bum" to "C:\tralala.bam".
C:\Users\elena\CopyNotExistingFile.proj(5,4): error MSB3021: Unable to copy file "C:\lalala.bum" to "C:\tralala.bam". Could not find file 'C:\lalala.bum'.
Done Building Project "C:\Users\elena\CopyNotExistingFile.proj" (default targets) -- FAILED.
ElenasTarget:
  BuildFailed=False
Done Building Project "C:\Users\elena\mytest.proj" (default targets).

Build succeeded.

My expectation was HasLoggedErrors would be set to true.

one way is to build self but with different target, for example your DefaultTargets one launches your custom MSBuildWrapper task pointing to itself (ie $(MSBuildProjectFile)) but with a different target that does other builds, copies

I’ve already tried it (that were my investigations I meant in my post). Unfortunately it doesn’t work either 🙁
(I am aware you said in theory).
My new single project looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="ElenasTarget" ToolsVersion="4.0">

    <UsingTask AssemblyFile="$(MSBuildProjectDirectory)\MyCompany.Tools.MSBuild.Tasks.dll" TaskName="MSBuildWithHasLoggedErrors" />

    <Target Name="ElenasTarget">
        <MSBuildWithHasLoggedErrors Projects="$(MSBuildProjectFile)" Targets="CopyNotExistingFile" ContinueOnError="true" >
            <Output TaskParameter="HasLoggedErrors" PropertyName="BuildFailed" />
         </MSBuildWithHasLoggedErrors>

         <Message Text="BuildFailed=$(BuildFailed)" />
  </Target>

  <Target Name="CopyNotExistingFile" >
         <Copy SourceFiles="C:\lalala.bum" DestinationFiles="C:\tralala.bam" />
  </Target>
</Project>

If I build this project HasLoggedErrors will still be set to false.
(Furthermore, my “real” build I’m currently maintaining is much complexer containing several project files with targets… so I can’t pack them all in a single project file ).

or writing custom logger and passing it through command line

That was my last hope!
My “real” build has a custom logger passed through the command line (I didn’t use it for my test project for the sake of simplicity). That is actually producing the log (a XML file) I’m going to parse to find out if any errors have been logged.
BTW, I thought the console logger is a kind of “global” logger. Am I wrong?

Anyway, the custom logger does not help neither, the Log.HasLoggedErrors is still set to false.
Is there some way I am not aware of to reference a particular logger (e.g. my custom logger) to ask if it has logged any errors?

It really looks like Log is scoped to individual targets.

Hmm… if the reflection on the buildengine instance is the last resort I would still prefer parsing the log.
(Don’t blame me! 🙂 )


My decision
After some investigations I’ve decided to stick with my initial solution: parse the log to find out if the build failed.

Check my comments to see why I prefer that to the suggestions have been provided so far.

If someone has some other ideas do not hesitate to share 🙂

(Otherwise this question can be closed, I suppose…)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T01:56:14+00:00Added an answer on June 5, 2026 at 1:56 am

    The MSBuildLastTaskResult reserved property will be set to True if the last task succeeded and False if the last task failed:

    <MSBuild Projects="@(ComponentToDeploy)"
             Targets="$(DeploymentTargets)"
             Properties="$(CommonProperties);%(AdditionalProperties)"
             ContinueOnError="true" 
             Condition="%(Condition)" />
    <Message Text="MSBuild failed!" Condition="'$(MSBuildLastTaskResult)' == 'False'" />
    

    I believe this was introduced with MSBuild v4.0.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom MSBuild task for xUnit.net. When the task is running, if
Using TeamCity running an MsBuild task for an MVC2 C# application, we successfully run
I am running a MSBUILD script which disables and enabled a scheduled task from
As part of some build automation of running xUnit.net tests with MSBuild , I'm
I'm trying to switch our build from CruiseControl.NET running a custom .msbuild file to
Ive got CC.Net and NAnt (and MSBuild) running on a new VM-based build server
I'm running a command using the msbuild Exec task. However I do not want
When running MSBUILD as part of an automated build process I get: MSBUILD :
I am running an external process in a custom msbuild task. This task is
I'm trying to integrate running Fitnesse tests from MSBuild im my nightly build on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.