NAnt ignoring property in included build file - nant

I'm trying to make my project build file include a local build file, to allow for some customization for each developer, without having to keep exclulding the build file from version control commits etc.
But NAnt keeps ignoring the properties in my included build file, and not overwriting the properties set in the global build file.
For demo purposes this short build file behaves the same:
<project name="FooProject" default="showme" basedir="." >
<description>Foo</description>
<!-- Overwrite this property in local.build -->
<property name="database.connectionstring" overwrite="true" readonly="false" value="foo" />
<include buildfile="local.build" failonerror="true" verbose="true" />
<target name="showme" description="Show connectionstring variable">
<echo message="Connectionstring: ${database.connectionstring}" />
</target>
</project>
-and my local.build file looks like this:
<property name="database.connectionstring" value="bar" />
The expected output when running NAnt with this build file is "Connectionstring: bar", but the resulit is "Connectionstring: foo", no matter which combination of readonly and overwrite I try.
It does fail if I rename the file to something else, so NAnt is aware of the included file.
NAnt is v0.91 alpha.
Am I overlooking something or is NAnt not supposed to work like I expect?

It seems you should still wrap the contents of the included build file inside a project-element. Like so:
<project>
<property name="database.connectionstring" value="bar" />
</project>
When I did that the connectionstring was "bar".
Granted: I use Nant 0.91 final.

Related

Phing update version number in XML manifest

I need to add the ability to a phing build to:
Parse an existing xml file within the project area to get an existing build number (in format 1.2.3)
Ask the user what type of 'change' this is (i.e. major, minor, fix)
Based on the response of the user at the time of run, upgrade the respective digit from the build number (if major increase 1 by 1; if minor increase 2 by 1; if fix increase 3 by 1)
Store the build number back into the original xml file
Have the new build number available for use when naming a zip file (later in the build).
Wondering if anyone already has a phing build file that does something like this or if you happen to know what phing tasks might help with these steps?
As a starting point you could do it without overhead using the version task (it uses a property file to store the version information) or with some more effort from a xml file.
The following example build script (documentation links can be found in the description attributes) contains both ways.
<?xml version="1.0" encoding="UTF-8" ?>
<project name="version test"
default="help"
phingVersion="3.0"
description="https://stackoverflow.com/questions/68584221/phing-update-version-number-in-xml-manifest"
>
<target name="help" description="usage help">
<echo>Usage:</echo>
<echo>bin/phing xml-file-based-workflow</echo>
<echo>bin/phing property-file-based-workflow</echo>
</target>
<target name="xml-file-based-workflow"
description="version handling with xml file"
depends="user-input,handle-xml-version,use-version"
/>
<target name="property-file-based-workflow"
description="version handling with property file"
depends="user-input,handle-property-version,use-version"
/>
<target name="user-input"
description="https://www.phing.info/guide/hlhtml/#InputTask"
hidden="true"
>
<input message="what is your release type?" propertyName="release.type" defaultValue="Bugfix"/>
</target>
<target name="handle-property-version"
description="https://www.phing.info/guide/hlhtml/#VersionTask"
hidden="true"
>
<version releasetype="${release.type}" file="VERSION.txt" property="version.number"/>
</target>
<target name="handle-xml-version"
description="
https://www.phing.info/guide/hlhtml/#XmlPropertyTask
https://www.phing.info/guide/hlhtml/#EchoPropertiesTask
https://www.phing.info/guide/hlhtml/#VersionTask
https://www.phing.info/guide/hlhtml/#DeleteTask
https://www.phing.info/guide/hlhtml/#EchoXMLTask
"
hidden="true"
>
<xmlproperty file="VERSION.xml" />
<echoproperties destfile="VERSION.txt" regex="/version\.number/"/>
<version releasetype="${release.type}" file="VERSION.txt" property="version.number"/>
<delete file="VERSION.txt"/>
<echoxml file="VERSION.xml">
<version>
<number>${version.number}</number>
</version>
</echoxml>
</target>
<target name="use-version"
description="https://www.phing.info/guide/hlhtml/#EchoTask"
hidden="true"
>
<echo message="${version.number}" />
</target>
</project>

CruiseControl.net, send dynamic values to some files

I have been searching for a few days, I have also asked a question on the cc.net forum, but still don't have the answer.
My task is to fill Web.config with specific values during the building using cc.net. Here is the example:
I'm developing an ASP.NET website, I have a Web.config with some configuration, e.g. connection string:
<add name="ContextName" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=DatabaseName;User Id = UserName;Password=UserPassword;" providerName="System.Data.SqlClient" />
After the building I want to replace some values and make the config look like this:
<add name="ContextName" connectionString="Data Source=%SERVER%;Initial Catalog=%DATABASE%;User Id = %USER%;Password=%PASSWORD%;" providerName="System.Data.SqlClient" />
I tried this solution, but it didn't help me (or maybe I didn't understand how to use it properly).
Please help me to solve the task.
Thanks!
You can try to use this Config Transformation Tool which is XDT transformation command tool based on XDT (web.config) transform engine, which allows you to run XDT transformation on any XML files. You can use ccnet's task block to run it after your msbuild
<tasks>
<exec>
</exec>
</tasks>
More on ccnet executable task see here.
For more information on XDT transformation see this link in MSDN library
You can create a target on your build file to update the web.config and call that target after the build. I use something similar in my build files, here is an example:
<target name="update-config" >
<property name="export.config" value="" unless="${property::exists('export.config')}" />
<call target="${config-settings}" /> <!-- test or stage -->
<xmlpoke file="${export.config}" xpath="/configuration/appSettings/add[#key='ContextName']/#connectionString" value="${configValue.connectionString}" failonerror="true" />
</target>
<target name="test">
<property name="configValue.connectionString" value="test connection string here" />
</target>
<target name="stage">
<property name="configValue.connectionString" value="stage connection string here" />
</target>
After executing the target that compile your code and export you can run the target update-config, in this case I'm expecting a variable export.config with the path of the exported web.config then calling another target that sets the the value of the connectionstring variable (this can be target test or stage) and finally xmlpoke the web.config with the value.
Hope this helps!

error while building project using Nant

I have file pro.build:
<?xml version="1.0" ?>
<project name="NAnt.NUnit2ReportTasks" default="build" basedir=".">
<sysinfo />
<target name="nunitreport">
<nunit2report out="HTML_TestResults.html">
<fileset>
<includes name="NUnitTestResult.xml" />
</fileset>
</nunit2report>
<echo message="HTML Test report generated." />
</target>
</project>
From command prompt(DOS), I am giving command,
Nant -buildfile:pro.build
But I am getting error
Target 'build' does not exist in this project
Can you help me resolving this?
With <project>'s default attribute you specify the target which should be executed if no other target is specified on the command line.
Problem: On the command line you're calling Nant -buildfile:pro.build so you are not specifying a target there. NAnt tries to execute default target build which is not present and fails.
Solution: Either you specify target nunitreport on the command line by calling Nant -buildfile:pro.build nunitreport. But since specifying a non-existent default target in your build file doesn't make much sense, I would suggest changing the default target:
<project name="NAnt.NUnit2ReportTasks" default="nunitreport" basedir=".">
<!-- ... -->
</project>
Specifing complete path for the buildfile could resolve the issue
nant –buildfile:"c:\FolderpathofAppdotbuildfileGoesHere\buildfilename.build"

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?

How can I automate compiling a large Java project?

I'm working on an automation project for my employer. We have a pool for each revision of our source code. When you download a revision, you need to create a directory structure with a bunch of third party includes to eventually build the project. I've automated this entire process up to the point of having my script (.bat) compile each particular runnable java application. There are many applications to this single project, and the directory listing looks something like this:
Proj Name
-variousincludesfolder1
-variousincludesfolder2
-variousincludesfolder3
-variousincludesfolder4
-runnableapplicationsandmoreincludes
-con.java
Right now, I'd like to do an automated compiling of con.java, but I don't know where to begin. People have suggested I try Ant, but any automated Ant file generation I get using Eclipse seems only enough to build con.java while an active project file exists. Is there anyway to automate this without using eclipse, to the point of having the batch file generate a .jar itself?
This is definitely a job for Ant. Don't rely on Eclipse-generated Ant files; read through the manual and write one yourself. (You'll likely find out that Ant does things you didn't think of doing in your build script, too.)
To be more specific, here is the documentation for the jar task.
You can define wildcard and pattern matches to include/exclude all sorts of files and folders in your build. Take a look at the Ant manual to see how things like filesets work with include and exclude filters.
Also, read the tutorial.
Here is a simple build file that looks to compile all java files and reference all jars. Place it in the top level directory:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl"
href="http://www.ibm.com/developerworks/xml/library/x-antxsl/examples/example2/ant2html.xsl"?>
<project name="Proj Name" default="build" basedir=".">
<property name="src.dir" value="${basedir}" description="base folder where the source files will be found. Typically under /src, but could be anywhere. Defaulting to root directory of the project" />
<property name="build.dir" value="build" description="Where to put build files, separate from src and resource files." />
<path id="master-classpath">
<fileset dir="${basedir}" description="looks for any jar file under the root directory">
<include name="**/*.jar" />
</fileset>
</path>
<target name="build" description="Compile all JAVA files in the project">
<javac srcdir="${src.dir}"
destdir="${build.dir}/classes"
debug="true"
deprecation="true"
verbose="false"
optimize="false"
failonerror="true">
<!--master-classpath is defined above to include any jar files in the project subdirectories(can be customized to include/exclude)-->
<classpath refid="master-classpath"/>
<!--If you want to define a pattern of files/folders to exclude from compilation...-->
<exclude name="**/realm/**"/>
</javac>
</target>
</project>