<?xml version="1.0" encoding="utf-8" ?>
<!-- **************************************************************
NAnt build-file for .Net VS2008-solutions (.Net 3.5), version 090224.
Usage guide:
1: Make sure you have Subversion-client installed (test by running "svn" at command prompt.)
(Client can be obtained here: http://www.sliksvn.com/en/download/)
2: Make sure you have "NAnt" installed. (Also NAntAddIn for Visual Studio can be used: http://www.netlogics.ch/en/nantaddin.download.html)
3: Put this file in the same folder as your solution file (.sln).
4: Include this file in your dotnet-solution ("add existing item"), this is just for easier editing of the file.
5: Modify variables "src_dir", "src_slnfile", "msbuild", "sln_build", "svn_gethead_cmd",
"assembly_file" and "release_batfile" to fit your needs.
6: Add the text-tag "@SVNREV@" to your "assembly_file", it will be replaced with subversion revision when this script is run.
7: Run this "nant_xmlscript.build"-file from "NAntAddIn", or by your own custom batch-file)
To use "NAntAddIn" with VS2008 you need to edit "NAntAddin.Addin", and specify "<Version>9.0</Version>".
More info: http://bchavez.bitarmory.com/archive/2008/07/13/nant-addin-for-visual-studio-vs-2008.aspx
8: If you get error "The device is not ready" from NAntAddIn, check your NAnt-path in the NAntAddIn "options".
9: The xml-block "release_make_upd" can be removed, if removed then also modify the "call-statements".
090224 nbn: Created first version of this build-file.
090224 nbn: Moved xml-block "revert" to the end, necessary for web-projects.
************************************************************** -->
<project name="dotnet_solution" default="init">
<property name="dquote" value='"' />
<property name="src_dir" value="." />
<property name="src_slnfile" value="${src_dir}\SQLEd.sln" />
<!-- MSBuild from .Net 3.5 is used, it does however support compiling into .Net 2.0 -->
<!-- MSBuild Command-line: http://msdn.microsoft.com/en-us/library/ms164311.aspx -->
<property name="msbuild" value="C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe" />
<property name="sln_build" value="release" /> <!-- debug|release -->
<property name="svn_gethead_cmd" value="info http://cqts0103:8080/svn/nilben/ --xml --revision HEAD" />
<property name="assembly_file" value="${src_dir}\Data\SQLEditor\SQL DB Edit\AssemblyInfo.vb" />
<property name="release_batfile" value="${src_dir}\sqled_make_upd_folder.bat" />
<!-- *** NANT-TARGET-1 *** -->
<target name="init" description="This is the 'init', NAnt processing should start here.">
<call target="get_headrevision" />
</target>
<!-- *** Unfortunately the "msbuild"-tag is not implemented in "NAnt v0.86 beta 1", code below probably needs the "NAntContrib" package..
<target name="compile_notused">
<echo message="Build Directory is ${output.dir}" />
<msbuild project="${Solution.Filename}">
<arg value="/property:Configuration=release" />
<arg value="/t:Rebuild" />
</msbuild>
</target>
-->
<!-- *** NANT-TARGET-2 *** -->
<target name="get_headrevision" description="This is where the 'revision-nr' is fetched from Subversion.">
<property name="tempfile" value="temp.txt" />
<exec program="svn.exe" commandline="${svn_gethead_cmd}" output="${tempfile}" />
<xmlpeek file="${tempfile}" property="revision" xpath="/info/entry/@revision" />
<delete file="${tempfile}" />
<call target="set_version" />
</target>
<!-- *** NANT-TARGET-3 *** -->
<target name="set_version" description="Assembly-file gets updated with previously fetched revision-nr.">
<script language="C#">
<code>
<![CDATA[
[TaskName("filepoke")]
public class FilePoke : Task {
private string _file;
private string _target;
private string _value;
[TaskAttribute("file", Required=true)]
public string TargetFile {
get { return _file; }
set { _file = value; }
}
[TaskAttribute("target", Required=true)]
public string Target {
get { return _target; }
set { _target = value; }
}
[TaskAttribute("value", Required=true)]
public string Value {
get { return _value; }
set { _value = value; }
}
protected override void ExecuteTask() {
string path = _file;
StringBuilder filecontents = new StringBuilder();
using (StreamReader sr = File.OpenText(path)) {
string s = "";
while ((s = sr.ReadLine()) != null) {
filecontents.Append(s.Replace(_target, _value) + "\n");
}
}
using (StreamWriter sw = new StreamWriter(path, false, System.Text.Encoding.UTF8)) {
sw.WriteLine(filecontents.ToString());
}
}
}
]]>
</code>
</script>
<!-- *** Loadfile works with replacetoken, but there is no way to save changes to file, "filepoke" is used instead..
<loadfile file="${assembly_file}" property="message">
<filterchain>
<replacetokens>
<token key="SVNREV" value="${revision}" />
</replacetokens>
</filterchain>
</loadfile>
<echo message="${message}" />
-->
<script language="C#" prefix="format" >
<code>
<![CDATA[
[Function("format-date")]
public static string FormatDate(DateTime date)
{
return date.ToString("yyyyMMdd-HHmm");
}
]]>
</code>
</script>
<filepoke file="${assembly_file}" target="@SVNREV@" value="${revision} (${format::format-date(datetime::now())})" />
<call target="final_build" />
</target>
<!-- *** NANT-TARGET-4 *** -->
<target name="final_build" description="Compiles using the specified Configuration">
<exec program="${msbuild}">
<arg value="${src_slnfile}" />
<arg value="/v:n" />
<arg value="/p:Configuration=${sln_build}" />
<arg value="/p:WarningLevel=0" />
<arg value="/p:SolutionDir=${src_dir}" />
</exec>
<call target="release_make_upd" />
</target>
<!-- *** NANT-TARGET-5 *** -->
<target name="release_make_upd" description="Run external batch-file 'make_upd' that copies files etc.">
<exec program="${release_batfile}" commandline="" />
<call target="svn_revert" />
</target>
<!-- *** NANT-TARGET-6 *** -->
<target name="svn_revert" description="Changes made to 'assembly-file' is reverted, to preserve the tag @SVNREV@ for next build.">
<exec program="svn.exe" commandline="revert ${dquote}${assembly_file}${dquote}" />
</target>
</project>