Hi,
 
I've stumbled upon the following serious bugs in NAnt :
 
when you want to execute a target (or task) only when a certain property has been set, you must use the unless attribute, like this :
 
 <target name="retrieve-NET-1.0-SdkRoot" unless="build.net10.sdkroot">
  <readregistry property="build.net10.sdkroot" key="SOFTWARE\Microsoft\.NETFramework\sdkInstallRoot" hive="LocalMachine" failonerror="true" />
 </target>
in this case, the target should only be executed if the "build.net10.sdkroot" was not already set (using the commandline or anywhere else) or if it was set and its value couldn't be converted to a boolean true value.
 
However, it seems as if there are actually three bugs in the way the if and unless attributes work in NAnt :
 
1. you can't directly specify a property name in the if and unless attribute, you must use ${ ...}
 
when I specify the property name directy (without ${...}) I get the following error message :
 
Cannot resolve to 'build.netcf10.sdkroot' to Boolean value.
 
The documentation clearly states :
 
if =  the name of the property that must be set in order for this target to execute.
unless = the name of the property that must not be set in order for this target to execute.
 
this is different from the way Ant works, you should be able to specify a property name directly in the if and unless attribute (not using the ${....} syntax)
 
2. when I specify the property name as ${propertyname}, I get the following error :
 
Property 'project.config' has not been set!
 
Which of course is true because the property has not been set, but that is exactly what the if and unless attribute are for : to check if a a property has been set or not and act accordingly.
 
The behaviour of the unless attribute should be :
 
- check if the property exists
- if  it doesn't exist, exeute the target or task
- if the property does exist, try to convert the value of the property to a boolean value
- if you can't convert it to a boolean value, consider the value to be "true" so don't execute the target or task
- if you can convert the value to a boolean, execute the task or target when the value is FALSE, DON'T execute it when the value is TRUE
 
The behaviour of the if attribute should be :
 
- check if the property exists
- if  it doesn't exist, don't exeute the target or task
- if the property does exist, try to convert the value of the property to a boolean value
- if you can't convert it to a boolean value, consider the value to be "true" and allow the target or task to be executed
- if you can convert the value to a boolean, execute the task or target when the value is TRUE, don't execute it when the value is FALSE
 
I'm pretty sure this is how it should work, and I'm pretty sure that's how Ant works !
 
3.  Apparently the if and unless attributes are evaluated before the dependent targets are executed, this is another major BUG.
 
The dependent targets should be executed before the unless or if are evaluated.  
This is how Ant does it, and this is how it should be done !
 
 
 
I think these are really show-stoppers, don't you agree ?
 
I included a very simple, sample build file to illustrate these issues !
 
Thanks,
 
Gert
 

Attachment: issues.build
Description: Binary data

Reply via email to