Re: Using "if" to test for existence of properties
Bob Archer <[email protected]>
| Newsgroups | gmane.comp.windows.dotnet.nant.user |
|---|---|
| Message-ID | <[email protected]> |
You can just use the overwrite attribute also. <property name="ernex.core.build" value="Latest" overwrite="false" /> We use this also to specify a default setting mostly for properties that will be set from the command line. debug mode for example. <property name="debug" value="false" overwrite="false" /> BOb From: Christopher Brandt [mailto:[email protected]] Sent: Tuesday, April 13, 2010 11:55 AM To: NAnt Users Cc: Durand Van Arnem; Bob Archer Subject: Re: [NAnt-users] Using "if" to test for existence of properties Same strategy here; ensure the property exists and then use the if attribute to test its value. One place where you can use the if / unless attributes to test existence is in setting the property itself, so giving it a default value. We use the following to ensure that required properties are at least set to a default value: <property name="ernex.core.build" value="Latest" unless="${property::exists('ernex.core.build')}" /> Hope that helps --- Chris. Continuous improvement is better than delayed perfection. - Mark Twain On Tue, Apr 13, 2010 at 7:51 AM, Bob Archer <[email protected]<mailto:[email protected]>> wrote: I think I have run into this before. I think the easiest fix is to make sure the property always exists. Then you can check to see if it is not empty. BOb From: Durand Van Arnem [mailto:[email protected]<mailto:[email protected]>] Sent: Tuesday, April 13, 2010 10:33 AM To: NAnt Users Subject: [NAnt-users] Using "if" to test for existence of properties Hello, I could use some advice about how to handle this situation: I have a property, MyProperty, that may or may not be set. I want a task to execute if the property is set, e.g. <echo messsage="Hello ${MyProperty}!" if="${property::exists('MyProperty')" /> If MyProperty is not set, this task fails because NAnt appears to evaluate the message portion regardless of the result of the IF evaluation. I could rewrite like this: <if test="${property::exists('MyProperty')}"> <echo message="Hello ${MyProperty}!" /> </if> However, I run into the same issue with filterchains: <!-- FAILS if MyProperty is not set, because NAnt evaluates the tokens regardless of the IF result --> <copy failonerror="true" verbose="true" todir="C:\Temp"> <fileset refid="Deploy-FileSet" /> <filterchain> <replacetokens begintoken="[" endtoken="]" ignorecase="true" if="${property::exists('MyProperty')}"> <token key="ABC" value="${MyProperty}" /> </replacetokens> </filterchain> </copy> I'd rather not enclose the whole definition of the copy in an IF, with a nearly identical "else" version for the case when MyProperty is not set. How have you handled this situation? Thanks, Durand ------------------------------------------------------------------------------ Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev _______________________________________________ NAnt-users mailing list [email protected]<mailto:[email protected]> https://lists.sourceforge.net/lists/listinfo/nant-users ------------------------------------------------------------------------------ Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev _______________________________________________ NAnt-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/nant-users