1、下载nant,nantcontrib,nunit,vss,fxcop,cruisecontrol.net,nunit2report
2、安装VSS,开发类库项目,单元测试项目,签入到VSS
3、解压nant,nantcontrib,nunit2report,安装fxcop和nunit,把nantcontrib和nunit2report的bin目录下的文件全部拷贝到nant的bin目录下。把nant.exe和fxcop.exe的目录设置到path的环境变量里。
4、建立一个目录,里面建立一个default.build文件和两个子目录,local和result,分别存放在VSS上获取的文件和编译的结果。
5、编写default.build文件,分别建立从vss获取项目文件,编译类库解决方案,编译单元测试解决方案,执行nunit,执行nunit2report,执行fxcop几个任务。最后建立一个bat文件,里面输入nant。运行nant就会自动执行这些任务了。
6、安装cc.net进入server目录,配置ccnet.config文件,运行ccnet.exe
------------
【示例】
1、我创建了D:\WorkTest\DailyBuild\Build目录,其下又创建了result和local目录
2、VSS的ini目录是\\10.2.11.39\vssData\,项目的路径是$/胡浩测试/Bank/,其下签入了个Bank的类库和Test的单元测试类库。
3、D:\WorkTest\DailyBuild\Build的目录下创建一个default.build文件,内容如下

 

实现dotnet的每日构建<?xml version="1.0" encoding="gb2312"?>
实现dotnet的每日构建
<!-- /*
实现dotnet的每日构建Default 指将要运行的target的名字。没有调用到的target将不执行。
实现dotnet的每日构建*/ 
-->
实现dotnet的每日构建
<project name="TestRemote" default="run" basedir=".">
实现dotnet的每日构建
<!-- /* 
实现dotnet的每日构建待编译的解决方案 
实现dotnet的每日构建     解决方案路径,及编译后输出路径。
实现dotnet的每日构建   这里一共是两个方案,即待测试项目和测试项目
实现dotnet的每日构建*/ 
-->
实现dotnet的每日构建     
<property name="Solution.Filename" value="D:\WorkTest\DailyBuild\Build\local\bank\bank.sln" />
实现dotnet的每日构建     
<property name="Solution.Configuration" value="DEBUG" />
实现dotnet的每日构建     
<property name="Build.OutputFolder" value="D:\WorkTest\DailyBuild\Build\result"/>
实现dotnet的每日构建
实现dotnet的每日构建    
<property name="Solution.Filename1" value="D:\WorkTest\DailyBuild\Build\local\test\test.sln" />
实现dotnet的每日构建     
<property name="Solution.Configuration1" value="DEBUG" />
实现dotnet的每日构建     
<property name="Build.OutputFolder1" value="D:\WorkTest\DailyBuild\Build\result"/>
实现dotnet的每日构建
<!-- /* 
实现dotnet的每日构建target t1 
实现dotnet的每日构建功能:把VSS里$/下所有文件下载到本地机 D:\WorkTest\DailyBuild\Build\local\ 目录中
实现dotnet的每日构建  User:VSS用户名, password :VSS密码 dbpath:服务器上srcsafe.ini的路径。
实现dotnet的每日构建*/ 
-->
实现dotnet的每日构建     
<target name="t1">
实现dotnet的每日构建         
<vssget user="huhao" password="huhao" localpath="D:\WorkTest\DailyBuild\Build\local\" dbpath="\\10.2.11.39\vssData\" path="$/胡浩测试/Bank/" />
实现dotnet的每日构建     
</target>
实现dotnet的每日构建
<!-- /*
实现dotnet的每日构建Target t2 依赖于t1,只要当t1正确执行才能执行t2
实现dotnet的每日构建功能:编译方案bank.sln
实现dotnet的每日构建*/ 
-->
实现dotnet的每日构建     
<target name="t2" depends="t1">
实现dotnet的每日构建          
<solution solutionfile="${Solution.Filename}" outputdir="${Build.OutputFolder}\" configuration="${Solution.Configuration}" />
实现dotnet的每日构建     
</target>
实现dotnet的每日构建
<!-- /*
实现dotnet的每日构建Target t3
实现dotnet的每日构建功能: 编译方案test.sln
实现dotnet的每日构建*/ 
-->
实现dotnet的每日构建     
<target name="t3">
实现dotnet的每日构建          
<solution solutionfile="${Solution.Filename1}" outputdir="${Build.OutputFolder1}\" configuration="${Solution.Configuration1}" />
实现dotnet的每日构建     
</target>
实现dotnet的每日构建
<!-- /*
实现dotnet的每日构建Target run
实现dotnet的每日构建功能:这个.build文件将要执行的target 
实现dotnet的每日构建Call : 指定本 target将要调用的target的名字,以先后的顺序执行
实现dotnet的每日构建*/ 
-->
实现dotnet的每日构建     
<target name="run">
实现dotnet的每日构建          
<call target="t1" /> 
实现dotnet的每日构建          
<call target="t2" />
实现dotnet的每日构建          
<call target="t3" />
实现dotnet的每日构建          
<call target="nunit" />
实现dotnet的每日构建          
<call target="fxcop" />
实现dotnet的每日构建     
</target>
实现dotnet的每日构建
<!-- /*
实现dotnet的每日构建Target nunit 
实现dotnet的每日构建功能:调用nunit并生成扩展名为.xml文件,以此来测试代码。
实现dotnet的每日构建Outputdir:输入路径设为根目录。
实现dotnet的每日构建Task  nunit2report是将生成的xml文件转化成.html格式,文件查看。
实现dotnet的每日构建*/ 
-->
实现dotnet的每日构建
<target name="nunit" depends="t3">  
实现dotnet的每日构建 
<nunit2>
实现dotnet的每日构建                
<formatter type="Plain" />
实现dotnet的每日构建         
<formatter type="Xml" usefile="true" extension=".xml" outputdir="." />
实现dotnet的每日构建                
<test assemblyname="D:\WorkTest\DailyBuild\Build\result\test.dll" />
实现dotnet的每日构建 
</nunit2>
实现dotnet的每日构建
<nunit2report>
实现dotnet的每日构建   
<fileset>
实现dotnet的每日构建    
<includes name="test.dll-results.xml" />
实现dotnet的每日构建   
</fileset>
实现dotnet的每日构建
</nunit2report>
实现dotnet的每日构建
</target>
实现dotnet的每日构建
<!-- /*
实现dotnet的每日构建Target fxcop 
实现dotnet的每日构建功能:调用fxcop这个文件来检测bank.dll这个文件是否符合事先定义好的代码规范,并以
实现dotnet的每日构建test.xml文件输出。
实现dotnet的每日构建Commandline: /f指要测试的程序集的路径和名称,/o 指输出XML文件的地址和名称。
实现dotnet的每日构建*/ 
-->
实现dotnet的每日构建
<target name="fxcop">
实现dotnet的每日构建
<exec program="fxcopcmd" commandline="/f:D:\WorkTest\DailyBuild\Build\result\bank.dll /o:test.xml" />
实现dotnet的每日构建
</target>  
实现dotnet的每日构建
</project>
实现dotnet的每日构建
实现dotnet的每日构建

4、在D:\WorkTest\DailyBuild\Build目录下新建run.bat,里面输入nant,双击run.bat就会自动运行了。这时会在本目录下生成test.xml,test.dll-results.xml,index.htm几个文件,分别是fxcop的代码分析文件,nunit的的xml报告,和nunit2report转换的html单元测试报告。打开这个htm文件就可以看到当前项目有多少个测试通过了。
5、在ccnet的server目录下修改ccnet.config文件,内容如下,然后运行ccnet.exe,这样就可以在有人签入代码的时候自动运行nant的任务了。

实现dotnet的每日构建<?xml version="1.0" encoding="gb2312"?>
实现dotnet的每日构建
<cruisecontrol>
实现dotnet的每日构建  
<project name="MyProject">
实现dotnet的每日构建    
<webURL>http://localhost/ccnet</webURL>
实现dotnet的每日构建    
<schedule type="schedule" sleepSeconds="6"/>
实现dotnet的每日构建
<!-- /*
实现dotnet的每日构建功能:监控VSS里是否有代码改动情况。
实现dotnet的每日构建Ssdir :本地机VSS的安装目录
实现dotnet的每日构建Executable:执行服务器上 ss.exe文件
实现dotnet的每日构建Project: 取得服务器上哪些文件
实现dotnet的每日构建Username: VSS登陆用户名  password:VSS登陆密码
实现dotnet的每日构建*/ 
-->
实现dotnet的每日构建    
<sourcecontrol type="vss" autoGetSource="true">
实现dotnet的每日构建                
<ssdir>D:\Program Files\vss\win32</ssdir>   
实现dotnet的每日构建
<executable>\\10.2.11.39\vssData\win32\ss.exe</executable>              
实现dotnet的每日构建  
<project>$/胡浩测试/Bank/</project>  
实现dotnet的每日构建  
<username>huhao</username>  
实现dotnet的每日构建  
<password>huhao</password>                     
实现dotnet的每日构建    
</sourcecontrol>
实现dotnet的每日构建
<!-- /*
实现dotnet的每日构建功能:让Nant去执行 d:\test\default.build文件。
实现dotnet的每日构建Executable:nant.exe文件的绝对路径。
实现dotnet的每日构建baseDirectory: .build文件的目录。
实现dotnet的每日构建buildFile: 将要build的文件的名字(nant一次只能执行一个.build文件)。
实现dotnet的每日构建*/ 
-->
实现dotnet的每日构建    
<build type="nant">
实现dotnet的每日构建      
<executable>D:\WorkTest\nant\bin\nant.exe</executable>
实现dotnet的每日构建      
<baseDirectory>D:\WorkTest\DailyBuild\Build</baseDirectory>    
实现dotnet的每日构建      
<buildFile>default.build</buildFile>  
实现dotnet的每日构建      
<targetList>
实现dotnet的每日构建        
<target>run</target>
实现dotnet的每日构建      
</targetList>
实现dotnet的每日构建      
<buildTimeoutSeconds>300</buildTimeoutSeconds>
实现dotnet的每日构建    
</build>
实现dotnet的每日构建    
<modificationDelaySeconds>10</modificationDelaySeconds>
实现dotnet的每日构建  
</project>
实现dotnet的每日构建
</cruisecontrol>
实现dotnet的每日构建

【链接】
在.NET环境中实现每日构建(Daily Build)--ccnet,MSBuild篇
http://www.cnblogs.com/hjf1223/archive/2006/04/13/374655.html
在.NET环境中实现每日构建(Daily Build)--NAnt篇
http://dragon.cnblogs.com/archive/2005/07/29/203189.html
《DailyBuild全攻略》V1.2版本发布,免费提供下载
http://www.cnblogs.com/coolbug/archive/2004/11/22/66954.html

相关文章: