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

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

Related

yGuard does not work in the simplest form possible (Hello World)

Here is my Ant snippet:
<target name="-post-jar">
<taskdef name="yguard" classname="com.yworks.yguard.YGuardTask" classpath="${javac.classpath}"/>
<yguard>
<inoutpair in="${dist.dir}/Valuemaze.jar" out="${dist.dir}/Valuemaze_obf.jar"/>
</yguard>
<copy file="${dist.dir}/Valuemaze.jar" tofile="${dist.dir}/Valuemaze_test.jar"/>
</target>
Classpath is ok, target runs as the second task (copy) works properly. So paths are ok.
yguard task does nothing. No any message, warning nor error is provided. Cannot configure any debug logging, yguard seems to have none.
What can be wrong?
It forced me to dig into yGuard sources.
And the answer is:
<target name="-post-jar">
<taskdef name="yguard" classname="com.yworks.yguard.YGuardTask" classpath="${javac.classpath}"/>
<yguard>
<inoutpair in="${dist.dir}/Valuemaze.jar" out="${dist.dir}/Valuemaze_obf.jar"/>
<rename mainclass="mypackage.myclass"/>
</yguard>
</target>
You have to add subtask to make it working.
Why does not docs specify this? Because it doesn't.
Why there is no single example for newbies in docs? Because it isn't.
Why there is no debug information about task missing? Because so.
Leaving here for other begginers.

NAnt: How to Load External NAnt Scripts Inside A Custom Task

In short, my problem is:
How to load an NAnt script in side a custom task, and execute it?
Detailed explanation:
In our current project build, we need to execute external programs. The external programs need to be located before the build kicks off. (coz it takes so looong time)
What I want is to have some NAnt module, like those FindXXX.cmake modules in CMake, so I can have modules like:
<?xml version="1.0"?>
<project name="FindSQLServerCore" default="FindSQLServer">
<target name="FindSQLServer">
<module>
<path>
<pathelement dir="C:\Program Files\Microsoft SQL Server\100\Tools\Binn" />
<pathelement dir="C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn" />
</path>
<files>
<file name="SQLCmd.exe" />
</files>
</module>
</target>
</project>
And when I need to include SQLServer in my build script, I can do:
<find module="SQLServer" required="true" />
My way to do it is by create 2 custom tasks: FindTask & ModuleTask.
FindTask is going to locate the FindXXX.include and loaded it into current NAnt project.
ModuleTask is going to find specified file under given path and return results.
But I cannot find ways to create & execute NAnt tasks by loading a build script in FindTask. The Project.CreateTask(XmlNode) only accepts node that is already loaded but not from newly loaded XML.
Is there a way to create task by loading a build script inside a custom task?
Or is my way doing this the NAnt style? Any better ways to achieve same goal?
PS. You might ask why not just use
<include file="FindSQLServer.include" />
The reason I'm not doing it this way is I want to pass the required parameter in, but not set it as a variable and pass it in.
You can get the NANT extension here:NAntFind#github
One way to load an NAnt script and execute it inside a custom task is to create a new project, and load the script using the project, then execute. Example:
var findProject = new Project(nantModule, Level.Info, Project.IndentationLevel);
findProject.Execute();
If the project fails, an exception should be thrown out.

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...

Setting PATH environment variable on ant build.xml works on cygwin but not on cmd or PowerShell

I was trying to set PATH enviroment variable on an ant build.xml through this answer.
It works on cygwin but not on cmd or PowerShell.
Some information:
Apache Ant 1.6.5 (I know there is a newer version (1.8.4), but for internal reasons I have to use this older version)
Powershell v2.0
cmd v6.1.7601
cygwin 2.774
Windows 7
You may need to use the exec task a little differently on Windows/cmd environments.
Let's use the windows command set as an example. set will print environment variables. A normal exec task running a set command might look like:
<exec executable="set" outputproperty="set.output">
<env key="MY_VAR" value="MY_VAL"/>
<echo message="${set.output}"/>
</exec>
But using this form of the exec task should throw an IOException: The system cannont find the file specified.
When running ant under windows cmd shell, the exec task can also be invoked via cmd, like this:
<exec executable="cmd" outputproperty="set.output">
<arg line="/c set"/>
<env key="MY_VAR" value="MY_VAL"/>
<echo message="${set.output}"/>
</exec>
This is the equivalent command; the actual command executed is cmd /c set, which is running set in a cmd sub-process.
The reason why this is necessary is only a little complicated and is due to the way that the commands are located by Win32 ::CreateProcess. The ant exec docs briefly explain this.
Note that I haven't tried either of these using PowerShell, so I have no experience which, if either, will work.
In my own ant build scripts I typically have two versions of each target that require special handling for windows platforms, with an isWindows test that looks like this:
<target name="check-windows">
<condition property="isWindows">
<os family="windows"/>
</condition>
</target>
Then I can switch between versions of the same task using:
<target name="my-target-notwindows" depends="check-windows" unless="isWindows>
...
</target>
<target name="my-target-windows" depends="check-windows" if="isWindows>
...
</target>
<target name="my-target" depends="my-target-notwindows,my-target-windows">
...
</target>
Unfortunatelly was an ant bug related to 1.6.5 version. I was able to update to 1.8.4 and everything works fine.

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?