static void

Nant template

Used by ccnet.config and assumes a C:\Build directory with subfolders Src, Deploy and Nant (containing Nant, of course). The two main targets are "production" (simple VSS get and build) and "full" (with a dependency dll, zipping up etc).

<?xml version="1.0"?>
<
project name="MyProject" default="production">
    <
description>MyProject NANT build script</description>
    <!--
properties used in this file -->
    <!--
this property will be overridden by cruisecontrol -->
    <
property name="ccnet.label" value="0"/>
    <!--
name of solution/project
    Assume Virtual directory  == solution == project name
    (if other projects, manually add webmap/map)
-->
    <
property name="build.projname" value="MyProjectName"/>
    <!--
build.outputpath - where the built code is put (see also project@basedir above) -->
    <
property name="build.rootpath" value="C:\Build"/>
    <
property name="build.outputpath" value="${build.rootpath}\Deploy"/>
    <
property name="build.srcpath" value="${build.rootpath}\Src"/>
    <!--
build.solutionpath -->
    <
property name="build.solutionpath" value="${build.rootpath}\Src"/>
    <
property name="build.localsolutionpath" value="C:\Visual Studio Projects\MyProject"/>
    <!--
VSS properties -->
    <
property name="build.srcsafeini" value="\\sshost\ssdirectory\srcsafe.ini"/>
    <
property name="build.srcsafepath" value="$/${build.projname}"/>
    <
property name="build.VssUserName" value="VssUserName"/>
    <!--
default task - build it and create deployment
    See also the task "full" below (used by CC.Net)
    -->
    <
target name="production" description="Build solution and copy production files">
        <!--
default project task- runs build, then deploy-->
        <
call target="clean"/>
        <
call target="build"/>
        <
call target="deploy"/>
    </
target>
    <!--
clean out the deploy directory-->
    <
target name="clean" description="Copy production files">
        <
delete dir="${build.outputpath}" failonerror="false"/>
    </
target>
    <!--
build target - the solution -->
    <
target name="build" description="Compile solution using Release configuration">
        <
solution solutionfile="${build.localsolutionpath}\${build.projname}.sln"
                  
configuration="Release" outputdir="${build.outputpath}\${build.projname}\bin">
            <
webmap>
                <!--
remap the url in solution to a local directory -->
                <
map url="http://localhost/${build.projname}/${build.projname}.vbproj"
                    
path="${build.srcpath}\${build.projname}\${build.projname}.vbproj"/>
            </
webmap>
            <
excludeprojects>
                <!--
include name="Test\NunitTests.vbproj"/-->
            </
excludeprojects>
        </
solution>
    </
target>
    <!--
create a deployment -->
    <
target name="deploy" description="Copy production files">
        <!--
Copy build results to Deploy folder -->
        <
copy todir="${build.outputpath}">
            <
fileset basedir="${build.srcpath}">
                <
include name="**.aspx"/>
                <
include name="**.html"/>
                <
include name="**.config"/>
                <
include name="**.gif"/>
                <
include name="**.jpg"/>
                <
include name="**.css"/>
                <
include name="**.js"/>
            </
fileset>
        </
copy>
        <!--
Reset attributes to Normal -->
        <
attrib normal="true">
            <
fileset basedir="${build.outputpath}">
                <
include name="**"/>
            </
fileset>
        </
attrib>
        <!--
how to change web.config
         <xmlpoke file="Build\Deploy\Web.config"
         xpath="/configuration/Templates/add
         [@key='TemplatesFolder']/@value"
         value="D:\inetpub\wwwroot\vdir\Templates" />
-->
    </
target>

    <!--
This is called from Cruise Control -->
    <
target name="full" description="Build solution and copy production files">
        <!--
default project task- runs build, then deploy-->
        <
delete dir="${build.srcpath}" failonerror="false"/>
        <
call target="getDependency"/>
        <
call target="getLatest"/>
        <
call target="buildFromVSS"/>
        <
call target="deployVSS"/>
        <
call target="FXCopReport"/>
    </
target>
    <!--
source safe task-->
    <
target name="getDependency" description="Get a dependency from source safe">
        <
mkdir dir="${build.srcpath}" failonerror="false"/>
        <
vssget username="${build.VssUserName}" password="" localpath="${build.srcpath}"
                
recursive="true" replace="true" writable="true"
                dbpath="${build.srcsafeini}" path="${build.srcsafepath}/Dependency"/>
        <
solution solutionfile="${build.solutionpath}\Dependency.sln"
                  
configuration="Release" outputdir="${build.srcpath}\${build.projname}\bin"/>
    </
target>
    <!--
source safe task-->
    <
target name="getLatest" description="Get the latest version of the code from source safe">
        <
mkdir dir="${build.srcpath}" failonerror="false"/>
        <
vssget username="${build.VssUserName}" password="" localpath="${build.srcpath}"
                
recursive="true" replace="true" writable="true"
                dbpath="${build.srcsafeini}" path="${build.srcsafepath}"/>
    </
target>

    <
target name="buildFromVSS" description="Compile solution using Release configuration">
        <
solution solutionfile="${build.solutionpath}\${build.projname}.sln"
                  
configuration="Release" outputdir="${build.outputpath}\bin">
            <
webmap>
                <!--
remap the url in solution to a local directory -->
                <
map url="http://localhost${build.projname}/${build.projname}.vbproj"
                    
path="${build.srcpath}\${build.projname}\${build.projname}.vbproj"/>
            </
webmap>
            <
excludeprojects>
                <!--
include name="Test\NunitTests.vbproj"/-->
            </
excludeprojects>
        </
solution>
    </
target>
    <!--
Copy to deployment directory and create a zip archive -->
    <
target name="deployVSS" description="Copy production files">
        <!--
Copy build results to Deploy folder -->
        <
copy todir="${build.outputpath}">
            <
fileset basedir="${build.srcpath}\${build.projname}">
                <
include name="**.aspx"/>
                <
include name="**.html"/>
                <
include name="**.config"/>
                <
include name="**.gif"/>
                <
include name="**.jpg"/>
                <
include name="**.css"/>
                <
include name="**.js"/>
            </
fileset>
        </
copy>
        <!--
Reset attributes to Normal -->
        <
attrib normal="true">
            <
fileset basedir="${build.outputpath}">
                <
include name="**"/>
            </
fileset>
        </
attrib>
        <
zip zipfile="${build.rootpath}\backup${ccnet.label}.zip">
            <
fileset basedir="${build.outputpath}">
                <
include name="**/*"/>
            </
fileset>
        </
zip>
    </
target>
    <
target name="FXCopReport">
        <
exec program="C:\Program Files\Microsoft FxCop 1.35\fxcopcmd.exe"
              
commandline="/f:C:\Build\Deploy\bin\${build.projname}.dll /o:C:\Build\fxcop.xml"
              
failonerror="false"/>
    </
target>
    <!--
Check in dll into VSS -->
    <
target name="checkin" description="Checkin latest dll">
        <
vsscheckin username="${build.VssUserName}" password=""
                    
localpath="${build.outputpath}\${build.projname}\bin\${build.projname}.dll"
                    
recursive="false" writable="true"
                    dbpath="${build.srcsafeini}"
                    
path="${build.srcsafepath}/bin/${build.projname}.dll"
                    
comment="ccnet build ${ccnet.label}"/>
        <
vsscheckout username="${build.VssUserName}" password=""
                    
localpath="${build.outputpath}\${build.projname}\bin\${build.projname}.dll"
                    
recursive="false" writable="true"
                     dbpath="${build.srcsafeini}"
                    
path="${build.srcsafepath}/bin/${build.projname}.dll"/>
    </
target>
</
project>