学习NAnt Build .CS+Solution+MSBuild+SVN+NUnit+NUnitReport

NAnt help:http://nant.sourceforge.net/release/latest/help/tasks/
NAntContrib help:http://nantcontrib.sourceforge.net/nightly/latest/help/tasks/index.html

下面有贴出代码,下载链接http://download.csdn.net/detail/dfg727/6614231
1.Build .CS files:
CSBat.bat
CSBuild.build

2.Build Solution By Solution:  some computer have error
SlnBat.bat
SlnBuild.build

3.Build Solution By Msbuild
MSBuild.bat
MSBuild.build
两种方法:
a.<target name="build" depends="clean">
        <!--<mkdir dir="bin"/>     -->
        <exec program="${msbuild.path}" commandline="${solution.file} /t:Rebuild /p:Configuration=${project.config} /v:q" workingdir="." />
    </target>

b.调用bat文件, msbuild命令写在bat中
nant调用bat文件
<target name="msbuild">
    <exec program="msbuild.bat"/>
</target>

/t:Rebuild|Clearn 生成目标
/p:Configuration=Debug|Release 项目属性
/l:FileLogger,Microsoft.Build.Engine;logfile=Build.log 编译日志
/clp:PerformanceSummary 显示任务、目标和项目花费的时间

bat命令:
C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/MSBuild.exe "F:/Test/NAntTest/Test1/test1.sln" /t:Build /p:Configuration=Debug

c.nant中用msbuild命令节点(需要NAntContrib)
MSBuild2.bat
MSBuild2.build

4.get svn code by exec run svn.exe:  增加到环境变量Path中 ;C:\Program Files\VisualSVN\bin;
svn.bat
svn.build

5.get svn code by NAntContrib:    增加到环境变量Path中 ;C:\Program Files\VisualSVN\bin;
svn2.bat
svn2.build

6.build NUnit files and run this dll to get test result, 文件中引用了其他的dll
Nunit.bat
Nunit.build     --为了增加测试结果的可读性,可以使用另一个工具NUnit2Report,将测试结果转换为直观的HTML文件。
NUnitTarget.cs
NUnitTarget2.cs

 

CSBuild.bat(调用NAnt文件CSBuild.build, 后面的调用就不贴了)

echo this is CSBuild.bat



echo params:%*



..\..\..\bin\nant\nant.exe -buildfile:CSBuild.build %* -logfile:CSLog.log



pause
View Code

 

CSBuild.build

<?xml version="1.0" encoding="gb2312"?>



<project name="Test" default="run" basedir=".">    

    <property name="dir.bin" value="bin" />

    <property name="file.exe" value="${dir.bin}\HelloWorld.exe" />

    

    <target name="run">

        <exec program="echoMessage.bat" />

        <call target="implement"/>

    </target>



    <target name="clean">

        <delete dir="bin" failonerror="false"/>

    </target>

    

    <target name="build" depends="clean">

        <mkdir dir="bin"/>     

        <csc target="exe" 

            output="${file.exe}">

            <sources>

               <include name="HelloWorld.cs"/>

            </sources>

        </csc>

    </target>



    <target name="implement" depends="build">

        <exec program="${file.exe}"/>

    </target>



</project>
View Code


HelloWorld.cs

using System;



class Hello

{

    static void Main()

    {

        Console.WriteLine("Hello");

    }

}
View Code


echoMessage.bat

echo. this is from echoMessage.bat
View Code

 

SlnBuild.build

<?xml version="1.0" encoding="gb2312"?>



<project name="Test" default="run" basedir=".">     

    <property name="Solution.Filename" value="D:\workspaces\WorkDemo\Work2008.sln"/>

    <property name="Solution.Configuration" value="DEBUG"/>

    <property name="Build.OutputFolder" value="bin"/>

    

    <target name="run">

        <call target="implement"/>

    </target>



    <target name="clean">

        <delete dir="bin" failonerror="false"/>

    </target>

    

    <target name="build" depends="clean">

        <!--<mkdir dir="bin"/>     -->

        <solution solutionfile="${Solution.Filename}" 

            outputdir="${Build.OutputFolder}"

            configuration="${Solution.Configuration}"/>

    </target>



    <target name="implement" depends="build">

        

    </target>



</project>
View Code

 

MSBuild.build

<?xml version="1.0" encoding="gb2312"?>



<project name="Test" default="run" basedir=".">     

    <property name="msbuild.path" value="${framework::get-framework-directory(framework::get-target-framework())}\msbuild.exe" />

    <property name="solution.file" value="D:\workspaces\WorkDemo\Work2010.sln"/>

    <property name="project.config" value="debug" />

    <property name="Build.OutputFolder" value="D:\workspaces\WorkDemo\WorkDemo.Tests\bin\Debug"/>

    <property name="Build.OutputFolder2" value="D:\workspaces\Learns\Nant\ExampleNet\bin"/>

    

    <target name="run">

        <call target="implement"/>

    </target>



    <target name="clean">

        <delete dir="bin" failonerror="false"/>

    </target>

    

    <target name="build" depends="clean">

        <!--<mkdir dir="bin"/>     -->

        <exec program="${msbuild.path}" commandline="${solution.file} /t:Rebuild /p:Configuration=${project.config};OutputPath=${Build.OutputFolder2} /v:q" workingdir="." />

    </target>



    <target name="implement" depends="build">        

    </target>



</project>
View Code

 

MSBuild2.build

<?xml version="1.0" encoding="gb2312"?>



<project name="Test" default="run" basedir=".">     

    <property name="msbuild.path" value="${framework::get-framework-directory(framework::get-target-framework())}\msbuild.exe" />

    <property name="solution.file" value="D:\workspaces\WorkDemo\Work2010.sln"/>

    <property name="project.config" value="debug" />

    <property name="Build.OutputFolder" value="D:\workspaces\WorkDemo\WorkDemo.Tests\bin\Debug"/>

    <property name="Build.OutputFolder2" value="D:\workspaces\Learns\Nant\ExampleNet\bin"/>

    

    <target name="run">

        <call target="implement"/>

    </target>



    <target name="clean">

        <delete dir="bin" failonerror="false"/>

    </target>

    

    <target name="build" depends="clean">

        <echo message="Building..." />



        <msbuild project="${solution.file}" verbosity="minimal" failonerror="true" verbose="false">

            <arg value="/p:Configuration=${project.config};OutputPath=${Build.OutputFolder2}" />

            <arg value="/p:UseWPP_CopyWebApplication=True" />

            <arg value="/p:PipelineDependsOnBuild=False" />

            <!--<arg value="/p:WebProjectOutputDir=${staging.output}\" />-->

            <arg value="/t:Rebuild" />

            <arg value="/nologo" />

        </msbuild>

        

        <echo message="Building finished..." />

    </target>



    <target name="implement" depends="build">        

        

    </target>



</project>
View Code

 

svn.build

<?xml version="1.0" encoding="gb2312"?>



<project name="Test" default="run" basedir=".">     

    <property name="svnUri" value="https://svn.code.sf.net/p/if01else/code-0/branches/20131124/Learns/Nant/testsolution/Hello" />

    <property name="workDir" value="SvnFolder"/>

    

    <target name="run">

        <call target="implement"/>

    </target>



    <target name="clean">

        <delete dir="${workDir}" failonerror="false"/>

    </target>

    

    <target name="build" depends="clean">

        <svn-checkout uri="${svnUri}" 

            destination="D:\ExampleNet" 

            username="ifelse01" password="if01else"/>



    </target>



    <target name="implement" depends="build">                

    </target>



</project>
View Code

 

svn2.build

<?xml version="1.0" encoding="gb2312"?>



<project name="Test" default="run" basedir=".">     

    <property name="svnLocation" value="C:\Program Files\VisualSVN\bin\svn.exe"/>

    <property name="svnUri" value="https://svn.code.sf.net/p/if01else/code-0/branches/20131124/Learns/Nant/testsolution/Hello" />

    <property name="workDir" value="SvnFolder"/>

    

    <target name="run">

        <call target="implement"/>

    </target>



    <target name="clean">

        <delete dir="${workDir}" failonerror="false"/>

    </target>

    

    <target name="build" depends="clean">

        <exec program="${svnLocation}" 

            commandline="checkout ${svnUri} ${workDir} --username ifelse01 --password if01else"/>

    </target>



    <target name="implement" depends="build">                

    </target>



</project>
View Code


Nunit.build   

<?xml version="1.0" encoding="gb2312"?>



<project name="Test" default="run" basedir=".">     

    <property name="dir.bin" value="bin" />

    <property name="file.dll" value="${dir.bin}\NUnitTarget.dll" />

    <property name="dir.report" value="report" />

    

    <target name="run">

        <call target="implement"/>

    </target>



    <target name="clean">

        <delete dir="bin" failonerror="false"/>

    </target>

    

    <target name="build" depends="clean">

        <csc target="library" 

            output="${file.dll}">

            <sources>

               <include name="NUnitTarget.cs"/>

               <include name="NUnitTarget2.cs"/>

            </sources>

            <references> 

                <include name="D:\workspaces\bin\nunit\nunit.framework.dll" />

            </references>

        </csc>

    </target>



    <target name="implement" depends="build">        

        

        <nunit2>

           <formatter type="Xml" usefile="true" extension=".xml" outputdir="${dir.report}" />

           <test assemblyname="${file.dll}" haltonfailure="false" />

        </nunit2>

        

        <nunit2report todir="${dir.report}" format="NoFrames">

            <fileset>

                <include name="${dir.report}/*.xml" />

            </fileset>

        </nunit2report>

    </target>



</project>
View Code


NUnitTarget.cs

using System;

using System.Collections.Generic;

using System.Text;

using NUnit.Framework;



namespace Test1

{

    [TestFixture]

    public class NUnitTarget

    {

        [Test]

        public void Test()

        {

            Assert.AreEqual(1, 1);

        }

        

        [Test]

        public void Test2()

        {

            Assert.AreEqual(1, 2);

        }

    }

}
View Code


NUnitTarget2.cs

using System;

using System.Collections.Generic;

using System.Text;

using NUnit.Framework;



namespace Test1

{

    [TestFixture]

    public class NUnitTarget2中文

    {

        [Test]

        public void Test中文()

        {

            Console.Write("NUnitTarget2.Test中文");

        }        

    }

}
View Code

 

 

 

 

 

你可能感兴趣的:(Build)