You can't use the if= attribute in a task statement to protect a reference to something else in that same task statement. All of the attributes to the task (in your case, <property>) are evaluated, then passed to the task body. So, by the time <property> sees that the if attribute is false, the XML interpreter has already evaluated ${msbuild.outputpath}.
You need to use an unconditional <property> task that is wrapped in a <if> task which checks the existence of ${msbuild.outputpath}. Merrill -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of David Jones Sent: Friday, February 16, 2007 10:55 AM To: nant-users@lists.sourceforge.net Subject: [NAnt-users] Problem setting a property conditionally where the value is a variable that may not have been set Hi folks, hope you can help me as it looks to me like this should be a very simple problem but I've been going round in circles. I have a target in an included build file to run msbuild on a .csproj file and it overwrites some of the settings in the proj file if certain nant properties are set. In particular I want to be able to set the OutputPath in msbuild only if there is a nant property 'msbuild.outputpath' set. My target is below: <target name="_msbuild" project="${msbuild.project}" description="Build using msbuild"> <msbuild target="${msbuild.target}" > <property if="${property::exists('msbuild.outputpath')}" name="OutputPath" value="${msbuild.outputpath}" /> </msbuild> </target> But when I run it with 'msbuild.outputpath' unset I get: Failed to start MSBuild. K:\nant\include.build(29,10): Property evaluation failed. Expression: ${msbuild.outputpath} ^^^^^^^^^^^^^^^^^^ Property 'msbuild.outputpath' has not been set. Total time: 0.1 seconds. But I thought if property::exists evaluates to false (as msbuild.outputpath is unset) the property task would not be evaluated. Am I missing something here, is it just not possible to stop nant processing the value argument of the property task? Is there maybe another way of achieving this without using an outer if block on the msbuild tas? Thanks Dave ------------------------------------------------------------------------ - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDE V _______________________________________________ NAnt-users mailing list NAnt-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/nant-users ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ NAnt-users mailing list NAnt-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/nant-users