Are the keywords used for project, target, task, function, ... in NAnt build files case sensitive or not?
Try this NAnt build script:
<?xml version="1.0" encoding="utf-8" ?>
<!-- ====================================================================== -->
<!-- test case sensitiveness -->
<!-- ====================================================================== -->
<project name="test.casesensitiveness" default="test">
<target name="test">
<property name="foo" value="bar" />
<echo message="Does property 'foo' exist? ${property::exists('foo')}" />
<echo message="Does property 'Foo' exist? ${property::exists('Foo')}" />
</target>
</project>
Here is the output:
test:
[echo] Does property 'foo' exist? True
[echo] Does property 'Foo' exist? False
So, yes identifiers in NAnt are case-sensitive.
In a word: Yes.
NAnt is case-sensitive, even if Windows isn't fussed.
Related
I'm following this tutorial
https://www.youtube.com/watch?v=jn6X-rx78ZU&list=PLJFgzBCcspK8p7Hxu2OLh-f-x0PBsIGjH&index=15&ab_channel=TheTutorialChef
and I'm trying to run the server at the end. NLog should output to console that server has started, but NLog is not outputting anything. I added the NLog config file below.
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
autoReload="true"
throwExceptions="false"
internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log">
<!-- optional, add some variables
https://github.com/nlog/NLog/wiki/Configuration-file#variables
-->
<variable name="myvar" value="myvalue"/>
<!--
See https://github.com/nlog/nlog/wiki/Configuration-file
for information on customizing logging rules and outputs.
-->
<targets>
<target name="Console" xsi:type="Console" layout=" ${level} ${date} ${message} ${exception:innerFormat=Message,StackTrace}" />
<!-- https://github.com/NLog/NLog/wiki/ColoredConsole-target -->
<target name="CConsole" useDefaultRowHighlightingRules="true" xsi:type="ColoredConsole" layout="${logger} ${level} ${date} ${message} ${exception:innerFormat=Message,StackTrace}" >
</target>
<target name="warnfile" xsi:type="File" fileName="${basedir}/Logs/warning.txt"
maxArchiveFiles="4"
archiveAboveSize="10240"
archiveEvery="Day" />
<target name="infofile" xsi:type="File" fileName="${basedir}/Logs/info.txt"
maxArchiveFiles="4"
archiveAboveSize="10240"
archiveEvery="Day" />
</targets>
<rules>
<!-- add your logging rules here -->
<logger name="*" minlevel="Info" maxlevel="Warn" writeTo="infofile" />
<logger name="*" minlevel="Warn" writeTo="warnfile" />
<logger name="*" minlevel="Trace" writeTo="CConsole" />
</rules>
</nlog>
But nothing outputs. There are no compilation errors or warnings. What have I done wrong? I'm using VSCode 2017, and NLog 4.7.6. I've tried editing the cofig file in the .nuget package directly. I've tried reinstalling NLog to get the original NLog.config, but now when I reinstall NLog, the config file doesn't appear in the root directory again.
The build script I am using:
<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." default="sass">
<target name="sass">
<apply dest="./sass" executable="sassy.bat">
<srcfile />
<targetfile />
<mapper from="*.scss" to="*.css" type="glob"/>
<fileset dir="./sass" includes="**/*.scss" />
</apply>
</target>
</project>
And it works great, with the condition that I have this external sassy.bat script on my %%PATH%%.
sass %1 %2
It compiles sass/*.scss files and puts the *.css in the same directory. However, if I don't use my sassy.bat and rather just use sass.bat it produces:
ruby.exe: Is a directory -- C:/project/sass (LoadError)
But in theory it should be running the same thing. Any idea what I'm doing wrong?
I ended up solving this problem recently. The first step is to ensure that the builder is set to use a "Separate JRE" (Zend Studio's). The second step was to update my buildfile to the following:
<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." default="sass">
<target name="sass">
<exec osfamily="windows" vmlauncher="false" executable="sass">
<arg value="--update" />
<arg value="scss/:css/" />
<arg value="--style=compressed" />
</exec>
</target>
</project>
The key was to set the vmlauncher attribute to false on Windows.
I have build.xml file and I want to create Java project from Existing Ant Buildfile. But I have an error: Specified buildfile does not contain a javac task
My file has simple structure:
<project>
<target ...>
</target>
...
</project>
Provide javac to your build.xml as below:
<javac srcdir="src" destdir="bin" />
As Puneet Pandey pointed out, this error occurs when your build.xml file is lacking a <javac> XML element.
The <javac> XML element in the build.xml file (referred to as javac task) tells the compiler or IDE (Eclipse in this case) where the source Java files are for compiling. Once you know that it should be quite clear why Eclipse can't import your build.xml without a <javac> XML element.
In case you are not sure where to stick the <javac> tag I'll add a slightly fuller example. You will need to navigate to your build.xml and edit it so that it contains the <javac> line in the appropriate section inside the <project> tag.
<project ...>
<javac srcdir="src" destdir="bin" />
<target ...>
</target>
...
</project>
You need something like this,
<target name="compile">
<javac destdir="build/classes" srcdir="src" includeantruntime="false">
<classpath refid="compile.classpath"/>
</javac>
</target>
<target name="war" depends="compile">
<war destfile="build/${name}.war" webxml="WebContent/WEB-INF/web.xml">
<fileset dir="WebContent" casesensitive="no">
</fileset>
<lib dir="WebContent/WEB-INF/lib"/>
<classes dir="build/classes">
</classes>
</war>
</target>
hi im doing a small application in the Zend Framework 1.8 Web Application Development book called storefront.
i have installed PHPUnit, version is PHPUnit 3.6.10 by Sebastian Bergmann. and also i installed apache ant.
as my ebook i create a build folder and run ant command inside of this folder via CMD
(folder contain ant.properties,build.xml files)
i got a BUILD FAILED message when execute ant command, there is a message in test section "unrecognized option --report"
here is my build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="StoreFront" default="build" basedir="../">
<target name="getProps">
<property file="${basedir}/build/ant.properties" />
<condition property="script-suffix" value=".bat" else="">
<os family="windows" />
</condition>
<echo message="---- Build Properties ----" />
<echo message="" />
<echo message="OS is ${os.name}" />
<echo message="Basedir is ${basedir}" />
<echo message="Property file is ${basedir}/build/ant.properties" />
<echo message="Script-suffix is ${script-suffix}" />
<echo message="" />
<echo message="---- Storefront Properties ----" />
<echo message="" />
<echo message="Environment is ${environment}" />
</target>
<target name="test" depends="getProps">
<exec dir="${basedir}/tests" executable="phpunit${script-suffix}" failonerror="true">
<arg line="--colors --report ${basedir}/build/report
--log-xml ${basedir}/build/logs/phpunit.xml
--log-pmd ${basedir}/build/logs/phpunit.pmd.xml
--log-metrics ${basedir}/build/logs/phpunit.metrics.xml
--coverage-xml ${basedir}/build/logs/phpunit.coverage.xml
AllTests.php"/>
</exec>
</target>
<target name="configure" depends="getProps">
<copy file="${basedir}/application/application.php.dist"
tofile="${basedir}/application/application.php" overwrite="true" />
<replace file="${basedir}/application/application.php" token="#ENVIRONMENT#" value="${environment}" />
</target>
<target name="buildPreparation">
<mkdir dir="${basedir}/build/logs" />
<mkdir dir="${basedir}/build/report" />
</target>
<target name="clean">
<delete dir="${basedir}/build/logs" />
<delete dir="${basedir}/build/report" />
</target>
<target name="build" depends="buildPreparation,configure,test"/>
</project>
here is the message i got in cmd
C:\wamp\www\storefront\build>ant
Buildfile: C:\wamp\www\storefront\build\build.xml
buildPreparation:
getProps:
[echo] ---- Build Properties ----
[echo]
[echo] OS is Windows 7
[echo] Basedir is C:\wamp\www\storefront
[echo] Property file is C:\wamp\www\storefront/build/ant.properties
[echo] Script-suffix is .bat
[echo]
[echo] ---- Storefront Properties ----
[echo]
[echo] Environment is development
configure:
[copy] Copying 1 file to C:\wamp\www\storefront\application
test:
[exec] PHPUnit 3.6.10 by Sebastian Bergmann.
[exec]
[exec] unrecognized option --report
BUILD FAILED
C:\wamp\www\storefront\build\build.xml:28: exec returned: 1
Total time: 0 seconds
C:\wamp\www\storefront\build>phpunit --version
PHPUnit 3.6.10 by Sebastian Bergmann.
how can i fixed this one im just following steps in the book
--report is not a valid command line switch in PHPUnit 3.6.
Please read the manual for valid options - http://www.phpunit.de/manual/current/en/textui.html#textui.clioptions
I have a nant file which does the building of my project. Once the build succeeded, I will use the nant.onsuccess property to send mail. In this nant.onsuccess I will call next batch of targets to build. But I need to send the mail depending on the success or failure of these set of targets that are called from the nant.onsuccess target.
eg:
<?xml version="1.0" encoding="utf-8" ?>
<project name="Build.build" default="default">
<property name="mail.mailhost" value="x"/>
<property name="mail.from" value="y"/>
<property name="mail.to" value="z"/>
<target name="default" description="Just like that">
<echo message="Succeeded"/>
<echo message="Succeeded"/>
<property name="nant.onsuccess" value="suc"/>
</target>
<target name="suc" description="Just like that">
<echo message="I am called"/>
<echo message="in success part"/>
<property name="nant.onsuccess" value="here"/>
<call target="testing"/>
</target>
<target name="testing">
<echo message="I ammmmmmmmmm"/>
<property name="nant.onsuccess" value="here"/>
</target>
<target name="here">
<echo message="I should not be called"/>
</target>
<target name="nant.onfailure">
<if test="${string::get-length(mail.to) > 0}">
<mail mailhost="${mail.mailhost}" from="${mail.from}" tolist="${mail.to}"
subject="Test mail on ${environment::get-variable('COMPUTERNAME')}.">
Note: this is ignored.
</mail>
</if>
</target>
</project>
The target "here" should be called depending on whether the target "testing" is succeeded or not.
Please let me know how do i achieve it.
Thanks,
Priya
Once nant finished its build it will execute a target specified by nant.onsuccess or nant.onfailure. This happens only once, so if you change the nant.onsucces / nant.onfailure properties it will have no effect.
As other posters stated for implementing conditional logic target dependencies, <if>, <trycatch>,<choose> and the <nant> and <call> tasks together with the if / unless attributes are better suited.
First thing to understand is how target dependencies can control execution. You can probably do a lot of what you need just by using dependencies. Read through the NAnt fundamentals page on targets.
Next, if you have to do a lot of logic depending on whether a particular task fails, you might check out the <trycatch> task in the NAntContrib project, which adds many useful tasks to NAnt. The trycatch task allows for a lot more flexibility than the default nant.onfailure.
I am not sure , if this will help. please give a look at below link.
I have put together a sample build file.
https://stackoverflow.com/a/11365488/1060656
<description>Sample Build Scripts</description>
<property name="nant.onsuccess" value="success" />
<property name="nant.onfailure" value="failure" />
<property name="tolist" value="youremail#email.com" />
<property name="cclist" value="youremail#email.com" />
<property name="emailsubject" value="" />
<target name="build" depends="init">
YOUR ACTUAL BUILD CODE GOES HERE
</target>
<target name="init">
<echo>
-----------------------------------------------------------------------------------------------------------------
TASK : INITIALIZE
-----------------------------------------------------------------------------------------------------------------
</echo>
<loadtasks assembly="nantcontrib-0.85/bin/NAnt.Contrib.Tasks.dll" />
<!-- http://www.basilv.com/psd/blog/2007/how-to-add-logging-to-ant-builds -->
<tstamp>
<formatter property="timestamp" pattern="yyMMdd_HHmm"/>
</tstamp>
<property name="build.log.filename" value="build_${timestamp}.log"/>
<echo message="build.log.filename: ${build.log.filename}" />
<record name="${build.log.dir}/${build.log.filename}" action="Start" level="Verbose"/>
<echo message="Build logged to ${build.log.filename}"/>
<echo message="Build Start at: ${datetime::now()}" />
</target>
<!--http://www.mail-archive.com/nant-users#lists.sourceforge.net/msg02485.html-->
<target name="success" depends="successresult,sendemail">
<echo>${emailsubject}</echo>
</target>
<!--http://www.mail-archive.com/nant-users#lists.sourceforge.net/msg02485.html-->
<target name="failure" depends="failureresult,sendemail">
<echo>${emailsubject}</echo>
</target>
<target name="successresult" >
<echo>
BUILD FAILED . CHANGE SUBJECT
</echo>
<property name="emailsubject" value="Web Integration DEV Build : SUCCESS !!!" />
</target>
<target name="failureresult" >
<echo>
BUILD FAILED . CHANGE SUBJECT
</echo>
<echo message="Task Start at: ${datetime::now()}" />
<property name="emailsubject" value="Web Integration DEV Build : FAILED !!! :)" />
</target>
<target name="sendemail" >
<echo>
-----------------------------------------------------------------------------------------------------------------
SENDING EMAIL
-----------------------------------------------------------------------------------------------------------------
</echo>
<echo message="Task Start at: ${datetime::now()}" />
<echo>${emailsubject}</echo>
<echo>Sending Email</echo>
<echo>Attaching File : ${build.log.dir}/email_${build.log.filename}</echo>
<echo>Attaching File : ${path.vsshelper.log}/logs/email_${build.log.getlistoffiles}</echo>
<!-- Flush is very important before you copy -->
<record name="${build.log.dir}/${build.log.filename}" action="Flush" level="Verbose"/>
<sleep milliseconds="1000" />
<!-- make a copy -->
<copy file= "${build.log.dir}/${build.log.filename}" tofile="${build.log.dir}/email_${build.log.filename}" />
<mail
from="${email.from}"
tolist="${email.to}"
mailhost="${email.host}"
message="${emailsubject}"
subject="${emailsubject}"
>
<attachments>
<include name="${build.log.dir}/email_${build.log.filename}" />
<include name="${path.vsshelper.log}/logs/email_${build.log.getlistoffiles}" />
</attachments>
</mail>
</target>