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

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.

Related

Missing output files after running Ant script from Eclipse

I have a simple web application developed in the Eclipse Luna. The directory structure of the application is like:
Project name is SchoolSchedule.
Under the project name, there are Java Resources, build, WebContent folders, and the build.xml file.
Under Java Resources, it is the "src" folder and my Java code package name is under the "src" folder.
Under the WebContent, there are META-INF, WEB-INF and my jsp files
Under the WEB-INF, there are web.xml file and the "lib" directory.
The build.xml is at the project root. This web application runs successfully and produces expected results.
I created an Ant script to compile, build a WAR file, and deploy the WAR. But, even the basic task does not work. I right click on the build.xml --> run as ... --> Ant build. In the console, I can see all the echo messages and no error. However, I do not see any new directories created (I "refresh" the project.). No "class" files compiled from the Java code and not to mention build and deploy those tasks.
There is something I did not get it right. Please help. Here is my Ant script:
<?xml version="1.0" encoding="UTF-8"?>
<project name="AntWarWebApp" basedir="." >
<echo>Define properties</echo>
<property name="name" value="SchoolSchedule"/>
<property name="src" location="src"/>
<property name="web" location="WebContent"/>
<property name="build" location="build"/>
<property name="classDir" location="${build}/src"/>
<property name="distDir" location="${build}/dist"/>
<property name="warDir" location="${build}/war"/>
<property name="tomcat.webapps" value="C:\apache-tomcat-7.0.70\webapps" />
<echo>time stamp</echo>
<tstamp prefix="build-info">
<format property="current-date" pattern="d-MMMM-yyyy" locale="en" />
<format property="current-time" pattern="hh:mm:ss a z" locale="en" />
<format property="year-month-day" pattern="yyyy-MM-dd" locale="en" />
</tstamp>
<echo>clean up previous build directories</echo>
<target name="clean" description="Delete old build directories">
<delete dir="${distDir}"/>
<delete dir="${warDir}"/>
<delete dir="${classDir}"/>
</target>
<echo>create directories</echo>
<target name="init" depends="clean">
<mkdir dir="${build}"/>
<mkdir dir="${classDir}"/>
<mkdir dir="${warDir}"/>
<mkdir dir="${distDir}"/>
<mkdir dir="${warDir}/WEB-INF"/>
<mkdir dir="${warDir}/WEB-INF/classes"/>
</target>
<echo>start compiling</echo>
<target name="compile" depends="clean, init" description="Compile main
source tree java files">
<javac srcdir="${src}" destdir="${classDir}" />
<classpath>
<fileset dir="${basedir}/WebContent/WEB-INF/lib">
<include name="*" />
</fileset>
</classpath>
</target>
<echo>start building WAR file</echo>
<target name="buildwar" depends="clean, init, compile">
<war basedir="${wardir}" destfile="${distDir}/${name}.war"
webxml="${wardir}/WEB-INF/web.xml">
<webinf dir="${wardir}/WEB-INF/">
<include name="**/*.jar" />
</webinf>
<manifest>
<attribute name="Built-On" value="${build-info.current-date}" />
<attribute name="Built-At" value="${build-info.current-time}" />
</manifest>
</war>
</target>
<echo>end building WAR file</echo>
<target name="deploy" depends="init, compile, buildwar" description="Deploy application">
<delete dir="${tomcat.webapps}/*.war" />
<echo>copy WAR file to Tomcat deploy directory</echo>
<copy file="${distdir}/*.war" todir="${tomcat.webapps}" />
</target>
</project>
Aren't you supposed to have some kind of top-level element
<project>
....
</project>
around all this?

How do I delete a folders that match pattern in phing

I have a build_ folders in my directory like build_10320 or build_10321.
I need to write a target clean that deletes such a folder.
I am trying doing this
<target name="clean">
<echo msg="clean directory ./build_" />
<delete includeemptydirs="true" verbose="true" failonerror="false" >
<fileset dir="./">
<include name="./build_*" />
</fileset>
</delete>
</target>
But this doesn't work. Kindly help.
Phing still doesn't have the <dirset> feature working (which would be the natural choice). You can however make this work using <exec> & the relevant command for deleting files from your operating system.
For linux:
<exec command = "rm -rf ./build_*" passthru = "true" />
A <fileset> returns, as the name suggests, only files.
There is an undocumented <dirset> type that unfortunately cannot be used with <delete> at the moment.
With Phing 3.x you can use <dirset> inside the <delete> task.
<project name="delete-with-dirset" default="clean" basedir=".">
<target name="clean">
<echo msg="clean directory ./build_" />
<delete includeemptydirs="true" verbose="true" failonerror="false">
<dirset dir="./">
<include name="./build_*" />
</dirset>
</delete>
</target>
</project>

Eclipse with Java EE (EJB), ANT and Jenkins / Hudson

My Goal is to get a Enterprise Java Application to be built on Jenkins. The Application consists of 4 Projects (Client-Interfaces, Webapplcation (incl. Faces), EJB Application (incl. JPA), EAR-Container-Project).
When Eclipse deploys this projects to a glassfish server, it assembles the Webapplication (war-file), the Client-Interfaces (jar-file) and the EJB-Interfaces (jar-file) into one ear-File.
Now, if I want to use continous integration I need to achieve the same on the CI-Server jenkins.
My first idea was to solve this with ant, so I used the Export-Function of Eclipse and generated build-Files for the projects.
The Problem is that the generated Build-Files refer to the Java EE Libraries (such as Glassfish-Runtime, JPA-Library, etc) which are outside of the project directory. There are about 30 libraries.
This implies that I cannot use the file on jenkins, because this libraries are missing. Of course I can copy these, but I don't think this is how it should be done.
So, what is the best way to get the Java EE Enterprise Application to be built on the CI Server? Do I have to write the ANT-Script all by myself and copy the libraries into the project? Or am I Missing something obvious?
Since I did not found anything that suited for me, I wrote an ant script that covered my needs on my own.
Here is my solution if this helps anyone in the future:
`
<project basedir="." default="build" name="Project">
<available property="glassfishdir" value="/opt/glassfish3/glassfish/modules"
file="/opt/glassfish3/glassfish/modules" type="dir" />
<!-- ########### Property Declarations ################################################################################################################### -->
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.6"/>
<property name="source" value="1.6"/>
<property name="builddir" value="build" />
<property name="outputartifacts" value="out" />
<property name="web.name" value="ProjectWeb" />
<property name="web.projectpath" value="ProjectWeb"/>
<property name="web.src" value="${web.projectpath}/src" />
<property name="web.builddir" value="${builddir}/web" />
<property name="web.builddir.classes" value="${web.builddir}/WEB-INF/classes"/>
<property name="ejb.name" value="ProjectEJB" />
<property name="ejb.projectpath" value="ProjectEJB"/>
<property name="ejb.src" value="${ejb.projectpath}/src"/>
<property name="ejb.builddir" value="${builddir}/ejb" />
<property name="ejb.builddir.classes" value="${ejb.builddir}/classes" />
<property name="ejbclient.name" value="ProjectEJBClient" />
<property name="ejbclient.projectpath" value="ProjectEJBClient"/>
<property name="ejbclient.src" value="${ejbclient.projectpath}/src"/>
<property name="ejbclient.builddir" value="${builddir}/ejbclient" />
<property name="ejbclient.builddir.classes" value="${ejbclient.builddir}/classes"/>
<property name="ear.name" value="ProjectApplication" />
<property name="ear.dir" value="ProjectEAR" />
<!-- ########### Main Targets ################################################################################################################### -->
<target name="build" depends="create-ear">
</target>
<target name="clean-build">
<antcall target="clean" />
<antcall target="build" />
</target>
<target name="clean">
<delete dir="${builddir}"/>
<delete dir="${outputartifacts}"/>
</target>
<target name="init">
<mkdir dir="${outputartifacts}" />
</target>
<!-- ########### EJB App ################################################################################################################### -->
<target name="init-ejb" depends="init">
<mkdir dir="${ejb.builddir}" />
<copy includeemptydirs="false" todir="${ejb.builddir.classes}">
<fileset dir="${ejb.src}">
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="build-ejb" depends="init-ejb">
<javac debug="true" debuglevel="${debuglevel}" destdir="${ejb.builddir.classes}" includeantruntime="false" source="${source}" target="${target}">
<src path="${ejb.src}"/>
<classpath>
<fileset dir="${glassfishdir}">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${outputartifacts}">
<include name="**/*.jar"/>
</fileset>
</classpath>
</javac>
</target>
<!-- ########### WEB ################################################################################################################### -->
<target name="init-web" depends="init">
<mkdir dir="${web.builddir.classes}"/>
<copy includeemptydirs="false" todir="${web.builddir}">
<fileset dir="${web.projectpath}/WebContent">
</fileset>
</copy>
<copy includeemptydirs="false" todir="${web.builddir.classes}">
<fileset dir="${web.src}">
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target depends="init-web,create-ejb-client" name="build-web">
<javac debug="true" debuglevel="${debuglevel}" destdir="${web.builddir.classes}" includeantruntime="false" source="${source}" target="${target}">
<src path="${web.src}"/>
<classpath>
<fileset dir="${glassfishdir}">
<include name="**/*.jar"/>
</fileset>
<fileset dir="out/">
<include name="**/*.jar"/>
</fileset>
</classpath>
</javac>
</target>
<!-- ############## EJB CLIENT ################################################################################################################ -->
<target name="init-ejb-client" depends="init">
<mkdir dir="${ejbclient.builddir}"/>
<copy includeemptydirs="false" todir="${ejbclient.builddir.classes}">
<fileset dir="${ejbclient.src}">
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target depends="init-ejb-client" name="build-ejb-client">
<javac debug="true" debuglevel="${debuglevel}" destdir="${ejbclient.builddir.classes}" includeantruntime="false" source="${source}" target="${target}">
<src path="${ejbclient.src}"/>
<classpath>
<fileset dir="${glassfishdir}">
<include name="**/*.jar"/>
</fileset>
</classpath>
</javac>
</target>
<!-- ############ CREATE ARCHIVES################################################################################################################## -->
<target name="create-web" depends="build-web">
<war destfile="${outputartifacts}/${web.name}.war" basedir="${web.builddir}" webxml="${web.projectpath}/WebContent/WEB-INF/web.xml"/>
</target>
<target name="create-ejb-client" depends="build-ejb-client">
<jar destfile="${outputartifacts}/${ejbclient.name}.jar" basedir="${ejbclient.builddir.classes}" includes="**/*"/>
</target>
<target name="create-ejb" depends="build-ejb">
<jar destfile="${outputartifacts}/${ejb.name}.jar" basedir="${ejb.builddir.classes}" includes="**/*">
<manifest>
<attribute name="Class-Path" value="${ejbclient.name}.jar"/>
</manifest>
</jar>
</target>
<target name="create-ear" depends="create-ejb-client,create-web,create-ejb">
<ear destfile="${outputartifacts}/${ear.name}.ear" appxml="${ear.dir}/EarContent/META-INF/application.xml">
<fileset dir="${outputartifacts}" includes="*.jar,*.war"/>
</ear>
</target>
</project>
`
Use Maven.
Maven allow to define all dependencies in a single xml file (pom), dependencies which will be automatically downloaded from internet at compilation phase.
Maven come with a set of plugin to facilitate continuous integration like being able to start a container, run the test and close it automatically.
Maven integrate natively with jenkins.
Maven defines a complex lifecycle designed for this kind of problematic and allowing to compile, run unit test, package, run integration test and deploy with a single command triggered from jenkins;
Maven is definitively THE solution here.
You can also auto-create the build.xml in Eclipse using "Export... > General\Ant Buildfile" from the project context menu. This way the correct classpath is generated to your JAR's already available in the project.
Chances are that if there are dependencies between the projects, you only need to configure one build file to be run on Jenkins, as it will automatically call the build files from the other projects.

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 and System.Data.Entity.dll

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}" />