Hi Edmund

I think I had a similar problem as yours. I wanted to build my project using
Nant and .sln (Visual Studio.NET 2003) solution file. This required that I
change some contents of the .sln file as  a part of the build process
(similar to assigning a new build version problem you have). However I
couldn't find an easy way (although there is one in ANT called Replace, NANT
doesn't have any equivalent) so this is what I did in my build.

<?xml version="1.0"?>
<project name="IPM" default="build" basedir=".\..">
    <!-- build.dir points to ipm -->
    <property name="build.dir" value="${nant.project.basedir}"/>
    
    <target name="build" depends="compile, unittests">
    </target>
    
    <target name="compile" depends="changeSlnFile">
        <echo message="${build.dir}"/>
        <solution configuration="debug" solutionfile="${build.dir}\ipm.sln"
failonerror="true"/>
    </target>
    
    <target name="unittests" failonerror="true">
        <nunit2>
            <test
assemblyname="${build.dir}\ipmtests\bin\Debug\ipmtests.dll"/>
        </nunit2>
    </target>
    
    <target name="changeSlnFile">
        <script language="C#">
            <code>
                <![CDATA[
                    public static void ScriptMain(Project project){
                        Console.WriteLine("***** " + project.BaseDirectory);
                        FileInfo fileInfo = new
FileInfo(project.BaseDirectory + "\\ipm.sln");
                        FileStream file = File.Open(fileInfo.ToString(),
FileMode.Open, FileAccess.ReadWrite);
                        StreamReader reader = new StreamReader(file);
                        string line = null;
                        line = reader.ReadToEnd();
                        if(line.IndexOf("http://localhost/ipm";) != -1)
                        {
                            //Console.WriteLine(line);
                            StringBuilder sb = new StringBuilder(line);
                            sb.Replace("http://localhost/ipm/";,
project.BaseDirectory+"\\");
                            line = sb.ToString();
                            reader.Close();
                            fileInfo.Delete();
                            Console.WriteLine(line); // output the changed
file contents just for verbosity
                            file =
File.Open(project.BaseDirectory+"\\ipm.sln", FileMode.CreateNew,
FileAccess.Write);
                            StreamWriter writer = new StreamWriter(file);
                            writer.AutoFlush = true;
                            writer.WriteLine(line);
                        }                       
                        file.Close();
                    }
                ]]>
            </code>
        </script>
    </target>
</project>

The main thing is the ScriptMain() ofcourse the algorithm could have been a
lot better but since I am new to the C# world ..... This might be one way
for you to increment build number when the build is successful.

As far as creating a build log is concerned I couldn't figure that out so I
am Draco.net http://draconet.sourceforge.net service for continous
integration. Though I still need to figure out how to schedule a build and
have the build log emailed to interested parties.

Hope this helps.

-daya sharma

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of Edmund Tan
Sent: Monday, August 18, 2003 4:01 AM
To: [EMAIL PROTECTED]
Subject: [Nant-users] Help with versiontask and build output log


Hi guys,
 
I'm a newbie when it comes to NAnt as i have just started writing a build
file to automate daily builds for my projects, and I'm currently facing 2
problems that I hope someone can hep me with.
 
The first is regarding the version task, i want to generate a build version
number each time it build but i cant find a way to do this, basically all i
want is to have the build version increment for every build automatically
and then assign this value to a property so i can use it throughout the
build script.
 
The second problem is i want the build to create a log file of the build
process. How do i do this? Initially i used the record task to write it to a
.txt file but it doesnt work.
 
FYI, I'm using nant version 0.8.3-rc2.
 
Would appreciate all the help i can get.
 
Edmund
NHS^?[){([ Zz?n 4D w%?6il&? x+ljwE?j zz0'?Z?z{^?0?v\bJ DNm ?brK?& 
??]4 M? Z?N M 55 ??f)+-5? X(?~zwi? l?q z l X)? ?

<<attachment: winmail.dat>>

Reply via email to