web development

How to fail ant builds with xbuild

While setting up a new mono (C# with xbuild) project with ant as build tool I discovered that xbuild always exits with return code 0.

Exit code 0 should always stand for “process finished, everything went fine” – ant consequently concludes that every xbuild run is a success… which is not always true.

Since I need that information to control wether to perform further steps in the project (auto-deployment to test system) or not, I am now scanning the xbuild output for “Build FAILED.” like this in my ant build.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project name="foobar" default="build" basedir=".">
    <target name="xbuild">
        <exec executable="xbuild" failonerror="true" dir="${basedir}" vmlauncher="false" outputproperty="xbuild.output" />
        <echo message="${xbuild.output}" />

    <target name="failbuild-on-error">
        <fail message="Build Failed">
                <contains string="${xbuild.output}" substring="Build FAILED." />

    <target name="build" depends="xbuild,failbuild-on-error"/>
Bookmark and Share

Related posts:

  1. Nagios: NRPE: Unable to read output error – check_apachestatus_auto.pl

2 Comments, Comment or Ping

  1. xbuild was actually returning 0 in a specific case, when one of the projects in a solution failed. That has already been fixed. You should see it in the next release.

    It would be better if you can test with the latest source or a snapshot tarball(www.mono-project.com), and file a bug (http://bugzilla.xamarin.com/index.cgi) if you still hit the problem.

  2. admin

    Hi Ankit,

    thank you for your comment. Nice to hear your insight and that it has already been fixed!

    But, being a debian user… this may take a while finding its way into stable.. ;)

Reply to “How to fail ant builds with xbuild”