MSBuild like NAnt allows conditions to be placed on all tasks, targets and the grouping elements for properties and items. Ant allows conditions on targets and a very small subset of tasks (basically <fail> and nothing else).

MSBuild and NAnt conditions can test for String (in)equality and file existence/absence. NAnt adds a couple of more conditions and supports boolean AND when multiple attributes are used. In Ant, the only condition you can test at the task/target level is whether a property has been set or not.

So Ant looks quite limited in comparison. Ant makes up for much of this via the condition task. With this, you can set properties based on conditions, those conditions can do all of the things that NAnt and MSBuild can do plus try to access HTTP URLs, connect to arbitrary sockets, compare file checksums, ... . On top of that, and/or/not are supported as boolean operations.

The Ant-Contrib project adds an <if> task that leverages Ant's condition framework, and I would rather add <if> to Ant than have all tasks support conditions. Otherwise you are going to repeat the same condition over and over again.

But then again, I've never had a build situation complex enough to ever use the <if> task (and I'm the author of it). The first example for conditionals you see in the MSBuild docs is

<PropertyGroup Condition="'$(Config)'== 'DEBUG'">
    <Property Optimize                  = "false"                    />
    <Property OutputPath                = "bin\Debug\"               />
    <Property WarningLevel              = "1"                        />
</PropertyGroup>

<PropertyGroup condition="'$(Config)'=='RETAIL'">
    <Property Optimize                  = "true"                     />
    <Property OutputPath                = "bin\Release\"             />
    <Property WarningLevel              = "4"                        />
</PropertyGroup>
in Ant, I'd use <pre class="code"> <property file="${config}.properties"/> </pre> and two property files instead. YMMV.

path: /en/dotNet/msbuild | #