Tuesday, April 17, 2007
Manually generation

In our previous artikel we talked about the NAnt build scripts.  We will show you a script that you can use to create your NAnt buildscripts.  This script can called manually. Later we will show you how you can do this fully automaticly.

For the easy generation of the Buildscripts, we have a buildscript generator. Running this will create the master.build file for a project. You have to change manually the name of the project when creating the master.build file for the next project (See red text in the example of a master.build file).

<?xml version="1.0" ?>
<project name="Tools.BuildScriptGenerator" default="GenerateBuildScript" xmlns="nant.xsd">

<!-- ################################################################################################### -->
<!-- GENERATE A NANT BUILD FILE FROM A VS.NET PROJECT -->
<!-- ################################################################################################### -->
<property name="file.out" value="generated.build" />
<property name="file.temp" value="${file.out}.temp" />
<property name="file.in" value="C:\Buildserver\Projects\<Your project folder>\<Project>Solution\<Project>.BL\<Project>.BL.csproj" />

<target name="GenerateBuildScript">
    <delete file="${file.out}" verbose="true" failonerror="false" />
    <delete file="${file.temp}" verbose="true" failonerror="false" />
    <style style="VSConvert.xsl" in="${file.in}" out="${file.temp}" />
    <loadfile file="${file.temp}" property="file" />
    <property name="newfile" value="${string::replace(file,'REPLACE_','')}" />
    <echo file="${file.out}" message="${newfile}" />
</target>

</project>

You can create a .Bat file for easy startup of the script generator. This is the code in your GenerateBuildScript.Bat file  :

@ECHO OFF
..\NAnt\bin\NAnt.exe -buildfile:master.build
PAUSE

while the buildscriptgeneration is running and you get an error “Unable to find source XML file ‘<<Project name>>’” this means that the path to your csproj file is wrong.  If you run the bat file, you get the file “generated.build”. This file must be copied to the project directory and renamed to master.build. In CruiseControl.Net, the automatic generation will also be added including this copy action.

Automaticilly generation

Now that we know how to let the computer generate our NAnt build scripts for a project, we can change this to let Cruisecontrol generates all the NAnt buildscripts for us and copy them in the correct place.  To do this, we will create a script called all.build.  This file contains all the project of our solution, will create for each project the master.build file and places it in the correct directory.

One important notice : I haven't found out how we can automate the building order of the projects, so this file must be maintained manually :-(.

OK, let's go to the script.  The lines marked in red must be changed manually :

<?xml version="1.0" ?>
<project name="<Project>.Complete" xmlns="
http://nant.sf.net/release/0.85-rc3/nant.xsd">
<!-- BuildServer Properties -->
<include buildfile="properties.build" />

<!-- Solution Properties -->
<property name="src.root.dir" value="${root.dir}/<Project name>" overwrite="false" />
<!-- Rebuild Master Scripts -->
<include buildfile="buildscripts.refresh.build" />
<call target="RefreshBuildScripts" />
<!-- Error Handling -->
<property name="nant.onfailure" value="<Project name>.Fail" />

<!-- Includes -->
<include buildfile="clean.build" />
<!-- Preparation -->
<call target="Clean" />
<!-- Project Properties -->
<property name="project.version" value="true" />
<property name="buildnumber.build" value="${CCNetLabel}" />
<property name="buildnumber.version" value="${buildnumber.build}" />
<property name="asm.version" value="${buildnumber.version}" />
<!-- projects -->
<include buildfile="<Project name>.Common/master.build" />
<call target="<Project name>.Common.Build" />
<include buildfile="<Project name>.DAL.AccessDbProvider/master.build" />
<call target="Fortisbank.<Project name>.AccessDbProvider.Build" />
<include buildfile="<Project name>.DAL/master.build" />
<call target="<Project name>.DAL.Build" />
<include buildfile="<Project name>.BL/master.build" />
<call target="<Project name>.BL.Build" />
<include buildfile="<Project name>.PL/master.build" />
<call target="<Project name>.Prototype.PL.Build" />
<!-- Web Applications Installation -->
<include buildfile="Webapplication.install.build" />
<call target="InstallWebApplications" />

<!-- CleanUp Sources -->
<!--<call target="<Project>.CleanSources" />-->
<!-- THE END -->
<!-- Remove Sources -->
<target name="<Project>.CleanSources">
    <delete>
        <fileset basedir="${src.root.dir}">
            <include name="**.*" />
            <exclude name="**.sln" />
            <exclude name="**.suo" />
        </fileset>
    </delete>
</target>

<!-- Fail -->
<target name="<Project>.Fail">
<!-- Remove sources -->
<call target="<Project>.CleanSources" failonerror="false"/>
</target>

</project>

As you can see, there are several blocks in the script :

  1. Buildserver properties : Properties of the buildserver
  2. Solution properties : Specific properties for that solution
  3. Refresh Master Scripts : Recreate the master.build files for each defined projects
  4. Error Handling
  5. Clean : This will clean up all the sources
  6. Project properties : specific project properties
  7. Projects : Declaration of the non-web projects that need to be build.  Be sure you put them in the correct building order.
  8. Web applications : Same as Projects, but for your web applications.

As you can see we make a difference between normal projects and web projects.  Why ? This will explained later.

Be sure to stayed tuned, because in the next chapter we will discuss a few build scripts which are called from within this script.  We also have to change our ccnet.config file.


Overview Buildserver chapters on my blog :

Chapter 1 : Introduction
Chapter 2 : CruiseControl.Net
Chapter 3 : Projects
Chapter 4 : Project Structure
Chapter 5 : NAnt and all our buildscripts
Chapter 6 : Buildscript generation Part 1

4/17/2007 8:13:22 AM (Romance Standard Time, UTC+01:00)  #     |