In NAnt, using the CSC task, how do I suppress compiler warnings? - nant

I see the CSC task in NAnt has a nowarn attribute, but apparently this is deprecated. How can I suppress warnings then?

Use the nowarn element instead. For example:
<csc output="${build.dir.legacy}Library.dll"
target="library"
verbose="${debug}">
<sources basedir="${source.legacy.patterns.dir}">
<include name="**.cs"/>
</sources>
<nowarn>
<warning number="0162,0169,0168,0219,0414,0649,0114,0105"></warning>
</nowarn>
</csc>

Related

getting the error " The <mail> type doesn't support the nested "attachments" element." with the below code

<project name="send email" default="send_email" basedir=".">
<target name="send_email">
<mail mailhost="inetmail.domain.com" subject="testing">
<from="testing#testing.com">
<tolist="testing#testing.com">
<message="Mail testing">
<attachments>
<fileset dir="E:\ContinuousIntegration\log">
<include name="Junit_status.txt"/>
</fileset>
</attachments>
</mail>
</target>
</project>
unable ro send an ant email with attachment: Error: The type doesn't support the nested "attachments" element."
The documentation for the mail task says,
Attachments may be sent using nested <attachments> elements … prior to Apache Ant 1.7 only <fileset> has been supported as a nested element, you can still use this directly without an <attachments> container.
Sounds like you’re using Ant 1.6 or earlier.
Remote the <attachments> and </attachments> lines and it should work.
1.Added "javax.mail.jar" to /lib folder
2.My ant is 1.6.5. Hence removed and and used directly.
These 2 steps resovled the issues

What should the contents of emma_ant.properties be?

I've been following this tutorial on 3. Getting Started (ANT), and it says <taskdef resource="emma_ant.properties" classpathref="emma.lib" /> but does not give any reference to the contents of emma_ant.properties. Any ideas?
Other websites such as 3.4. How do I change an EMMA property default setting? also leave things to be desired (and is based on the command prompt and not a digital file). I've found another website Using EMMA with ANT for JUnit test coverage reporting, but again it leaves the properties file to the imagination (doesn't even provide an example file).
Any ideas on how to manipulate the emma_ant.properties to Load and custom tasks for ANT?
but does not give any reference to the contents of emma_ant.properties. Any ideas?
Check for emma.jar & emma_ant.jar which you have placed in the path specified you will find emma_ant.properties
Any ideas on how to manipulate the emma_ant.properties to Load and custom tasks for ANT?
You need not to manipulate the properties file to use the tasks.
To use emma tasks you should
<!-- directory that contains emma.jar and emma_ant.jar -->
<property name="emma.dir" value="${YOUR_BASE_DIR}/lib/emma" />
<!-- Set emma.lib to refer to the list of EMMA jar files -->
<path id="emma.lib">
<fileset dir="${emma.dir}">
<include name="*.jar" />
</fileset>
</path>
and
<!-- Load <emma> custom tasks so that they can be used in ANT -->
<taskdef resource="emma_ant.properties" classpathref="emma.lib" />
and you should be able to use emma tasks.
Here are the contents of emma_ant.properties inside emma.jar
# -------------------------------------------------------------
emma: com.vladium.emma.emmaTask
emmajava: com.vladium.emma.emmajavaTask
# -------------------------------------------------------------
# end of file
Also Check out Emma Property Summary if it helps you...

How do I suppress warnings in NAnt when using the solution task?

We have a .NET 1.1 solution that we are compiling using NAnt with a "solution" task.
One of the projects throws multiple warnings for missing XML comments. I know which warnings I need to suppress (from http://bytes.com/topic/net/answers/177026-suppress-missing-xml-comment-warning-during-compile), but I can't see how. The csc task has a configuration element that can be used for this, but I can't see an equivalent for solution.
Is this even possible? How can I do it?
Replace NAnt's <solution> task by NAntContrib's <msbuild> task. You can pass solution files to MSBuild as well as project files and you can pass MSBuild properties like WarningLevel then. Find an example here.
I tend to prefer running an exec task for msbuild. This will suppress all warnings:
<exec program="${msbuild_exe_path}">
<arg line='"${solution_path}"' />
<arg line="/property:WarningLevel=0" />
<!-- SNIP -->
</exec>
More info on warning level settings: http://msdn.microsoft.com/en-us/library/13b90fz7.aspx
Getting msbuild to work on .net 1.1: http://blogs.msdn.com/b/jomo_fisher/archive/2004/11/29/271748.aspx

Include/Exclude buildfiles

How do you do this? Given several build files, I only want to include the ones where the target (specified from the command line) exists. Using target::exists in does not seem to work. Thanks.
<target name="*">
<property name="curr.target" value="${target::get-current-target()}"/>
<nant target="${curr.target}">
<buildfiles>
<include name="*.build" if="${target::exists(curr.target)}"/>
<!-- avoid recursive execution of current build file-->
<exclude name="${project::get-buildfile-path()}" />
</buildfiles>
</nant>
</target>
Using robaker's solution, my final build file looks like this. It does not fail anymore if the target is not found in a certain build file (unlike my previous code).
<project>
<include buildfile="A.build"/>
<include buildfile="B.build"/>
<target name="*">
<nant target="${target::get-current-target()}"/>
</target>
</project>
Why not just use the include task to include all your child build scripts instead?

Is it possible to override nant targets from included buildfile?

I have a generic common.xml file that holds a number of generic nant targets that are re-used among multiple builds. What I want to do is 'override' some of these nant targets and include additional steps either before or after the existing target is executed.
Are nant targets used from the current file first? ie. If i create a nant target in the current buildfile with the same name as a target in an included file does that one get called and the included one ignored? If that's the case I can just do and call the included target but it would seem like then that would be a recursive call rather then to an included task.
Thoughts?
I had the same question (and found the same results), but I also found a workaround. Allow me to illustrate with an example.
You have a ProjectFile.build and a CommonFile.build. Let's say you want to overwrite a target called "Clean".
You would need to create a new file (call it CommonFile_Clean.build) which contains:
<?xml version="1.0"?>
<project>
<target name="Clean">
<echo message="Do clean stuff here" />
</target>
</project>
In CommonFile.build, you conditionally include CommonFile_Clean.build:
<?xml version="1.0"?>
<project>
<echo message="checking Clean definition..." />
<if test="${not target::exists('Clean')}">
<echo message="Clean target not defined." />
<include buildfile="CommonFile_Clean.build" />
</if>
</project>
In ProjectFile.build, you can either define the Clean target (in which case CommonFile_Clean.build will not be used) or use the default implementation as defined in CommonFile_Clean.build.
Of course, if you have a large number of targets, this will be quite a bit of work.
Hope that helps.
No, I've just tried it for you, as I have a similar set-up, in that I have all of the build targets we use in a commonFile.build and then use the following code to bring it in...
<include buildfile="../commonFile.build"/>
In my newFile.build (that includes the commonFile.build at the top of the file), I added a new target called 'build', as it exists in the commonFile, and here's the error message you get in response...
BUILD FAILED
Duplicate target named 'build'!
Nice idea, probably bourne of OO principles, but sadly it doesn't work.
Any good?