Hey All, Currently we indeed do not treat the if/unless attributes in a special way.
Even if the if/unless attributes signal that a given target/task should not be executed, all elements/attributes will be initialized and it's up to task authors to check whether or not to use a given element (based on the IfDefined and UnlessDefined properties). I'd like to change our design here by intercepting this in our task/element initialization and first checking the values of the if/unless attributes. If the if/unless attributes indicate that the task/element should not be initialized, then further initialization would be skipped and the task/element would not be added to the containing struct (eg. target or task). That way, task authors will only get tasks/elements that actually need to be executed/initialized and no longer need to check the IfDefined/UnlessDefined properties. I still need to look into it a little further, to find a way to achieve this without breaking backward compatibility. Gert -------------------------------------------------- From: "Roebuck, Alex" <[EMAIL PROTECTED]> Sent: Wednesday, June 04, 2008 10:54 AM To: "Roebuck, Alex" <[EMAIL PROTECTED]>; "Schley Andrew Kutz" <[EMAIL PROTECTED]>; <nant-users@lists.sourceforge.net> Subject: Re: [NAnt-users] Bug discovered: The If and Unless tagsevaluateafterproperties are checked for existence > I might have over-complicated this. > > Are you saying that NAnt evaluates the value attribute before the if > attribute in the following line? > > <property name="compile.nunit.path" > value="${environment::get-variable('NUNIT_LIB_DIR')}" > if="${environment::variable-exists('NUNIT_LIB_DIR')}"/> > > This works fine for me, with no NAnt exceptions. > > Regards, > > Alex. > > > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Roebuck, > Alex > Sent: Wednesday, June 04, 2008 9:08 AM > To: Schley Andrew Kutz; nant-users@lists.sourceforge.net > Subject: Re: [NAnt-users] Bug discovered: The If and Unless tags > evaluateafterproperties are checked for existence > > Could you provide more information? > > On which statement were you using an "if test"? > > Use ${environment::variable-exists('name')} for testing environment > variables. > Use ${property::exists('name')} for testing NAnt properties. > > For example: > > <target name="test.target"> > <echo message="Will not be echoed" > if="${environment::variable-exists('test')}"/> > <echo message="Will not be echoed" > if="${property::exists('test')}"/> > <echo message="Env variable does not exist" > unless="${environment::variable-exists('test')}"/> > <echo message="Prop does not exist" > unless="${property::exists('test')}"/> > > <property name="test" value="true"/> > > <echo message="Will not be echoed" > if="${environment::variable-exists('test')}"/> > <echo message="Property exists" > if="${property::exists('test')}"/> > <echo message="Env variable does not exist" > unless="${environment::variable-exists('test')}"/> > <echo message="Will not be echoed" > unless="${property::exists('test')}"/> > </target> > > Gives: > > NAnt 0.85 (Build 0.85.2478.0; release; 14/10/2006) > Copyright (C) 2001-2006 Gerry Shaw > http://nant.sourceforge.net > > Buildfile: file:///C:/test.build > Target framework: Microsoft .NET Framework 2.0 > Target(s) specified: test.target > > test.target: > > [echo] Env variable does not exist > [echo] Prop does not exist > [echo] Property exists > [echo] Env variable does not exist > > BUILD SUCCEEDED > > Total time: 0.3 seconds. > > Alex. > > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Schley > Andrew Kutz > Sent: Tuesday, June 03, 2008 5:57 PM > To: nant-users@lists.sourceforge.net > Subject: [NAnt-users] Bug discovered: The If and Unless tags evaluate > afterproperties are checked for existence > > Ex. > > <!-- get the path to the nunit lib dir on the server (if it exists) --> > <property name="compile.nunit.path" value="null" /> > <if > test="${environment::variable-exists('NUNIT_LIB_DIR')}"> > <property > name="compile.nunit.path" > > value="${environment::get-variable('NUNIT_LIB_DIR')}" > > if="${environment::variable-exists('NUNIT_LIB_DIR')}"/> > </if> > > <!-- compile the main assembly --> > <csc target="library" > > output="${build}/${proj.name.unix}-${proj.version}.test.dll" > > doc="${docs}/${proj.name.unix}-${proj.version}.test.xml" > warninglevel="0"> > <sources> > <include name="src/**/*.cs" /> > </sources> > <references> > <!-- > if this is being run on a build > server then reference > the nunit files on the server, > otherwise reference the files > from the tools directory > --> > <include > name="${compile.nunit.path}/*.dll" /> > <include > name="../../tools/nunit-2.5-alpha1/net-2.0/lib/*.dll"/> > <include > name="../../src/${proj.name}/${build}/${proj.name.unix}-$ > {proj.version}.dll"/> > </references> > </csc> > > Notice my if statement. I *was* using an if test when setting the > property and then when including it in the references block. However, > NAnt kindly informed me that compile.nunit.path did not exist. Well, > duh -- that is what I was checking. Apparently NAnt evaluates whether > properties exist BEFORE it evaluates the IF and UNLESS expressions. > > I consider this to be a bug, but it may be by design... > > -- > -a > > "condensing fact from the vapor of nuance" > > > ------------------------------------------------------------------------ > - > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > NAnt-users mailing list > NAnt-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/nant-users > > ------------------------------------------------------------------------ > - > Check out the new SourceForge.net Marketplace. > It's the best place to buy or sell services for > just about anything Open Source. > http://sourceforge.net/services/buy/index.php > _______________________________________________ > NAnt-users mailing list > NAnt-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/nant-users > > ------------------------------------------------------------------------- > Check out the new SourceForge.net Marketplace. > It's the best place to buy or sell services for > just about anything Open Source. > http://sourceforge.net/services/buy/index.php > _______________________________________________ > NAnt-users mailing list > NAnt-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/nant-users > ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php _______________________________________________ NAnt-users mailing list NAnt-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/nant-users