NAnt and System.Data.Entity.dll - nant

I am new to NAnt and trying to set up a build file to build a few .Net 4.0 projects and run some NUnit tests. One of the projects contains an EF4.0 Data Model and context and I am running into an issue that even though the System.Data.Entity.dll reference is being included in the NAnt config, none of the System.Data classes contained in it are being found by the build (System.Data.EntityClient, System.Data.Objects, etc). I am using NAnt 0.91 Alpha 2. Anyone else run into this or have any idea how to get around it? Build file below.
Thanks.
<?xml version="1.0" encoding="utf-8" ?>
<project name="ClinicalModel">
<property name="src.dir" value="" />
<property name="output.dir" value="bin/debug" />
<property name="entitysrc" value="..\Entities" />
<property name="debug" value="true" overwrite="false" />
<property name="nant.settings.currentframework" value="net-4.0" />
<property name="framework-get-assembly-directory" value="${framework::get-assembly-directory('net-4.0')}" />
<property name="dotNetReferenceAssemblyPath" value="${framework-get-assembly-directory}\" />
<target name="clean" description="clean up already built files">
<delete file="${output.dir}/Entities.dll" failonerror="false" />
<delete file="${output.dir}/Model.dll" failonerror="false" />
</target>
<target name="build_entities" description="build entities">
<csc target="library" output="${output.dir}\Entities.dll" debug="${debug}">
<sources basedir="${entitysrc}">
<include name="**/*.cs" />
</sources>
</csc>
</target>
<target name="build" depends="build_entities" description="build model">
<csc target="library" output="${output.dir}\Model.dll" debug="${debug}">
<sources>
<include name="**\*.cs" />
</sources>
<references basedir="${output.dir}">
<include name="**\*.dll" />
</references>
</csc>
</target>
</project>

This may not be the solution you are looking for but I would recommend letting msbuild do the actual build work. Since you don't want to build the entire solution you would end up making 4 calls (one for each project you want to build) to msbuild. Here is a snippet from my root build script:
<property name="common.msbuild2010" value="C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\MsBuild.exe" />
<property name="common.buildType" value="Debug" />
...
<setenv>
<variable name="DevEnvDir" value="C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\"/>
</setenv>
<exec program="${common.msbuild2010}" commandline=""${local.someCsProjName}" /t:Rebuild /p:Configuration=${common.buildType}" />

Related

How to combine 3 steps in ant build.xml into one step for Netbeans to generate a signed jar to run in web start?

My web start app ran fine, but I realized there is a lib dir I need to copy into the tomcat ROOT dir in order for my web start app to work, but I want to just combine all my jars into one big jar so I just need to copy one file each time I update the project. I searched on the web and found a solution to combine all jars into one, with the following step, which was mentioned at : http://arunasujith.blogspot.com/2011/08/how-to-build-fat-jar-using-netbeans.html
I rewrote my build.xml to look like this :
<project name="Test_Tool" default="default" basedir=".">
<description>Builds, tests, and runs the project Test_Tool.</description>
<import file="nbproject/build-impl.xml"/>
<target name="package-into-one-jar" depends="jar">
<property name="store.jar.name" value="Test_Tool"/>
<!-- don't edit below this line -->
<property name="store.dir" value="dist"/>
<property name="store.jar" value="${store.dir}/${store.jar.name}.jar"/>
<echo message="Packaging ${application.title} into a single JAR at ${store.jar}"/>
<jar destfile="${store.dir}/temp_final.jar" filesetmanifest="skip">
<zipgroupfileset dir="dist" includes="*.jar"/>
<zipgroupfileset dir="dist/lib" includes="*.jar"/>
<manifest><attribute name="Main-Class" value="${main.class}"/></manifest>
</jar>
<zip destfile="${store.jar}"><zipfileset src="${store.dir}/temp_final.jar" excludes="META-INF/*.SF, META-INF/*.DSA, META-INF/*.RSA"/></zip>
<delete file="${store.dir}/temp_final.jar"/>
<delete dir="${store.dir}/lib"/>
</target>
</project>
But when I ran it, it said there are some files unsigned, and can't run from html page, so I did some more search and found a way to sign the jar file, which is mentioned at : http://www.asjava.com/ant/how-do-i-sign-jar-files-in-ant/
So I've come up with an script [ sign_jar.xml ] look like this :
<?xml version="1.0"?>
<project name="ant to create keystore and sign jars" default="signjars" basedir=".">
<tstamp/>
<property name="build.output.dir" value="C:/Dir_Test_Tool/dist"/>
<property name="build.classes.dir" value="C:/Dir_Test_Tool/dist"/>
<property name="verisign.key.store" value="${build.output.dir}/.keystore"/>
<property name="verisign.key.storepass" value="asjava.com"/>
<property name="verisign.key.alias" value="asjava"/>
<property name="verisign.key.pass" value="asjava.com"/>
<target name="signjars">
<mkdir dir="${build.output.dir}"/>
<genkey alias="${verisign.key.alias}" verbose="true" storepass="${verisign.key.storepass}"
keypass="${verisign.key.pass}" validity="365" keystore="${verisign.key.store}">
<dname>
<param name="CN" value="AsJava.com Group"/>
<param name="OU" value="Jim"/>
<param name="O" value="AsJava.com"/>
<param name="C" value="US"/>
</dname>
</genkey>
<signjar jar="${build.classes.dir}/Test_Tool.jar"
signedjar="${build.output.dir}/Test_Tool.jar"
alias="${verisign.key.alias}"
storepass="${verisign.key.storepass}"
keystore="${verisign.key.store}"
keypass="${verisign.key.pass}"/>
</target>
</project>
After all the changes, I needed to do the following to get the signed big jar file :
<1> Build my project in Netbeans
<2> In files view of the project right click build.xml file and then select Runtarget >> Other Targets >> package-into-one-jar
<3> In files view of the project right click sign_jar.xml file and then select Runtarget >> signjars
Now it works as I wished : One big jar that is signed.
But that's 3 steps in order to achieve this, there must be an easier way, why can't it be done in one step ? So I combined the above files into one, which looked like this :
<?xml version="1.0" encoding="UTF-8"?>
<project name="Test_Tool" default="default" basedir=".">
<description>Builds, tests, and runs the project Test_Tool.</description>
<import file="nbproject/build-impl.xml"/>
<target name="package-into-one-jar" depends="jar">
<property name="store.jar.name" value="Test_Tool"/>
<property name="store.dir" value="dist"/>
<property name="store.jar" value="${store.dir}/${store.jar.name}.jar"/>
<echo message="Packaging ${application.title} into a single JAR at ${store.jar}"/>
<jar destfile="${store.dir}/temp_final.jar" filesetmanifest="skip">
<zipgroupfileset dir="dist" includes="*.jar"/>
<zipgroupfileset dir="dist/lib" includes="*.jar"/>
<manifest><attribute name="Main-Class" value="${main.class}"/></manifest>
</jar>
<zip destfile="${store.jar}"><zipfileset src="${store.dir}/temp_final.jar" excludes="META-INF/*.SF, META-INF/*.DSA, META-INF/*.RSA"/></zip>
<delete file="${store.dir}/temp_final.jar"/>
<delete dir="${store.dir}/lib"/>
</target>
<property name="build.output.dir" value="c:/asjava"/>
<property name="build.classes.dir" value="C:/Dir_Test_Tool/dist"/>
<property name="verisign.key.store" value="${build.output.dir}/.keystore"/>
<property name="verisign.key.storepass" value="asjava.com"/>
<property name="verisign.key.alias" value="asjava"/>
<property name="verisign.key.pass" value="asjava.com"/>
<target name="signjars">
<mkdir dir="${build.output.dir}"/>
<genkey alias="${verisign.key.alias}" verbose="true" storepass="${verisign.key.storepass}"
keypass="${verisign.key.pass}" validity="365" keystore="${verisign.key.store}">
<dname>
<param name="CN" value="AsJava.com Group"/>
<param name="OU" value="Jim"/>
<param name="O" value="AsJava.com"/>
<param name="C" value="US"/>
</dname>
</genkey>
<signjar jar="${build.classes.dir}/Test_Tool.jar"
signedjar="${build.output.dir}/Test_Tool.jar"
alias="${verisign.key.alias}"
storepass="${verisign.key.storepass}"
keystore="${verisign.key.store}"
keypass="${verisign.key.pass}"/>
</target>
</project>
But the strange thing is : now it copies all the compiled directories under src into dist, if I delete them the result big jar won't run, I don't know ant good enough to correctly combine the above 3 steps into one, and don't know Netbeans enough to solve this problem, can someone help ?

error CS0246: The type or namespace name 'Form1' could not be found

Currently I am developing a NAnt script to build a Windows forms application. After build the NAnt script, I am getting the error as
error CS0246: The type or namespace name 'Form1' could not be found
(are you missing a using directive or an assembly reference? )
BUILD FAILED
C:\Program
Files\NAnt\examples\SampleWindowsApplication\Sample.Build(24,10):
External Program Failed:
C:\Windows\Microsoft.NET\Framework\v3.5\csc.exe (return code was 1)”
Can anyone please advise to resolve this issue?
Please find my code below.
<?xml version="1.0"?>
<project name="SampleWindowsApplication" default="run">
<property name="basename" value="SampleWindowsApplication"/>
<property name="debug" value="true"/>
<target name="clean">
<delete>
<fileset>
<include name="bin/${basename}-??.exe"/>
</fileset>
</delete>
</target>
<target name="build">
<mkdir dir="bin" />
<assemblyfileset id="Sample.assemblies">
<include name="C:\Program Files\NAnt\examples\SampleWindowsApplication\SampleWindowsApplication\Assemblies\Sam.Grid.Base.dll" />
<include name="C:\Program Files\NAnt\examples\SampleWindowsApplication\SampleWindowsApplication\Assemblies\Sam.Grid.Windows.dll" />
<include name="C:\Program Files\NAnt\examples\SampleWindowsApplication\SampleWindowsApplication\Assemblies\Sam.Shared.Base.dll" />
<include name="C:\Program Files\NAnt\examples\SampleWindowsApplication\SampleWindowsApplication\Assemblies\Sam.Shared.Windows.dll" />
<!--<include name="C:\Program Files\NAnt\examples\SampleWindowsApplication\SampleWindowsApplication\Assemblies\System.Windows.Forms.dll" />-->
</assemblyfileset>
<csc target="exe" output="bin/${basename}.exe" debug="${debug}" >
<references refid="Sample.assemblies" />
<resources>
<include name="C:\Program Files\NAnt\examples\SampleWindowsApplication\SampleWindowsApplication\licenses.licx"/>
</resources>
<sources>
<include name="C:\Program Files\NAnt\examples\SampleWindowsApplication\SampleWindowsApplication\Program.cs"/>
</sources>
</csc>
</target>
<target name="run" depends="build">
<exec program="bin/${basename}-cs.exe" basedir="."/>
</target>
</project>
Thanks in advance.
This is typically cause when you add a new file to your solution but don't commit them.
Check to make sure that Form1.cs and Form1.Designer.cs have been added to your source control repository. It looks like your project file was added and committed correctly but some source control tools require you to manually add new files before committing them.

Jenkins with JSLint and Violations plugin

I currently configured a jenkins server that validates my project on javascript errors with JSlint ( with ant). Now i want to show all the errors with the violation plugin. I can generate an xml with all the errors. But it doesn't show this in the graph.
This is my build.xml:
<?xml version="1.0" encoding="UTF-8"?>
<taskdef name="jslint"
classname="com.googlecode.jslint4java.ant.JSLintTask"
classpath="jslint/jslint4java-2.0.2.jar" />
<property name="reports.dir" value="reports" />
<target name="clean" description="Removes output files created by other targets.">
<delete dir="${reports.dir}" failonerror="true" />
</target>
<target name="jslint" depends="clean">
<mkdir dir="reports" />
<jslint options="white,undef,plusplus,newcap,vars,indent=4">
<predef>jQuery, setTimeout, history, window, document</predef>
<formatter type="xml" destfile="jslint_results.xml"/>
<fileset dir="" includes="**/*.js" excludes="lib/*.js" />
</jslint>
</target>
This is my violations setting:
The pattern is relative to your workspace. So if your report 'lives' in <WORKSPACE>/reports the pattern should be reports/jslint_results.xml or **/jslint_results.xml

Nant "nant.onsuccess" property

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>

nant mail issues

Can anyone please suggest me how we could configure the sending of mails through nant.I had even gone through the link but i was unsucessfull.
thanks and regards
maddy
Something like this is what you would use.
<target name="sendmail">
<mail
from=“NAnt#myCompany.com“
tolist=“${distribution_list}“
subject="${mailsubject}"
mailhost="${smtpServer}"
message="${mailbody}"
verbose="true"
>
<attachments>
<include name="${buildroot}/build.log" />
</attachments>
</mail>
</target>
Here is a sample build file. The solution is not very elegant but it works. All it does is logs a file and before sending email flush it and makes a copy of it to attach it in email.
Note: there are some help links in code which i used while writing my own build file.
<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>