Re: Using "if" to test for existence of properties
Bob Archer <[email protected]>
| Newsgroups | gmane.comp.windows.dotnet.nant.user |
|---|---|
| Message-ID | <[email protected]> |
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]] 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] https://lists.sourceforge.net/lists/listinfo/nant-users