本文主要是介绍【乔梁】用Nant和Nunit构建C#项目,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
以前没使用Nant和Nunit建立过C#代码的自动化构建,今天自己写了一个C#程序,想用Nant和Nunit构建C#代码。可写好build文件后运行UnitTest时遇到了麻烦。命令行提示如下:
查了一下资料解决了这个问题。
解决方法是:
一、在该程序的config文件(如果程序名是money.dll,则该文件名为money.dll.config)中加入如下代码:
二、使用VS2005提供的gacutil把nant.core.dll 和 nant.framework.dll注册一下。具体做法是:
1、在window开始菜单用运行VS所带的Visual Studio 2005 Command Prompt。
2、切换到nunit的bin目录下
3、顺序运行下列命令
三、大功告成。
现在运行 nant unittest 就完事大吉。
附 nant 的 build 文件如下:
Could not load file or assembly 'nunit . framework , Version = 2.4 . 3.0 , Culture = neutral , PublicKeyToken = 96d09a1eb7f44a77' or one of its dependencies . The system cannot find the file specified .
查了一下资料解决了这个问题。
解决方法是:
一、在该程序的config文件(如果程序名是money.dll,则该文件名为money.dll.config)中加入如下代码:
xml version="1.0" encoding="utf-8" ?>
< configuration >
< runtime >
< assemblyBinding xmlns ="urn:schemas-microsoft-com:asm.v1" >
< dependentAssembly >
< assemblyIdentity name ="nunit.framework" publicKeyToken ="96d09a1eb7f44a77" culture ="Neutral" />
< bindingRedirect oldVersion ="2.0.6.0" newVersion ="2.4.3.0" />
< bindingRedirect oldVersion ="2.1.4.0" newVersion ="2.4.3.0" />
dependentAssembly >
assemblyBinding >
runtime >
configuration >
< configuration >
< runtime >
< assemblyBinding xmlns ="urn:schemas-microsoft-com:asm.v1" >
< dependentAssembly >
< assemblyIdentity name ="nunit.framework" publicKeyToken ="96d09a1eb7f44a77" culture ="Neutral" />
< bindingRedirect oldVersion ="2.0.6.0" newVersion ="2.4.3.0" />
< bindingRedirect oldVersion ="2.1.4.0" newVersion ="2.4.3.0" />
dependentAssembly >
assemblyBinding >
runtime >
configuration >
二、使用VS2005提供的gacutil把nant.core.dll 和 nant.framework.dll注册一下。具体做法是:
1、在window开始菜单用运行VS所带的Visual Studio 2005 Command Prompt。
2、切换到nunit的bin目录下
3、顺序运行下列命令
gacutil / i nunit.core.dll // 注册core
gacutil / i nunit.framework.dll //注册framework
gacutil / l //查看是否注册上
gacutil / i nunit.framework.dll //注册framework
gacutil / l //查看是否注册上
三、大功告成。
现在运行 nant unittest 就完事大吉。
附 nant 的 build 文件如下:
xml version="1.0" ?>
< project name ="CSharpMoney" default ="ut" >
< property name ="output.dir" value ="../bin" />
< property name ="output.dll" value ="../bin/cs-money.dll" />
< property name ="reports.dir" value ="../reports" />
< target name ="clean" >
< delete dir ="${output.dir}" />
< delete dir ="${reports.dir}" />
target >
< target name ="copyfile" depends ="clean" >
< mkdir dir ="${output.dir}" unless ="${directory::exists(output.dir)}" />
< copy file ="../nunit/bin/nunit.framework.dll" todir ="${output.dir}"
if ="${file::exists('nunit/bin/nunit.framework.dll')}" />
target >
< target name ="build" depends ="copyfile" >
< csc target ="library" output ="${output.dll}" debug ="true" >
< sources >
< include name ="*.cs" />
sources >
< references >
< include name ="../nunit/bin/nunit.framework.dll" />
references >
csc >
target >
< target name ="ut" depends ="build" >
< mkdir dir ="${reports.dir}" />
< exec program ="..NUnit unit-console.exe" >
< arg value ="${output.dll}" />
< arg value ="/config=cs-money.dll.config" />
< arg value ="/xml=${reports.dir}TestReport-Unit.xml" />
< arg value ="/nologo" />
< arg value ="/noshadow" />
exec >
target >
project >
< project name ="CSharpMoney" default ="ut" >
< property name ="output.dir" value ="../bin" />
< property name ="output.dll" value ="../bin/cs-money.dll" />
< property name ="reports.dir" value ="../reports" />
< target name ="clean" >
< delete dir ="${output.dir}" />
< delete dir ="${reports.dir}" />
target >
< target name ="copyfile" depends ="clean" >
< mkdir dir ="${output.dir}" unless ="${directory::exists(output.dir)}" />
< copy file ="../nunit/bin/nunit.framework.dll" todir ="${output.dir}"
if ="${file::exists('nunit/bin/nunit.framework.dll')}" />
target >
< target name ="build" depends ="copyfile" >
< csc target ="library" output ="${output.dll}" debug ="true" >
< sources >
< include name ="*.cs" />
sources >
< references >
< include name ="../nunit/bin/nunit.framework.dll" />
references >
csc >
target >
< target name ="ut" depends ="build" >
< mkdir dir ="${reports.dir}" />
< exec program ="..NUnit unit-console.exe" >
< arg value ="${output.dll}" />
< arg value ="/config=cs-money.dll.config" />
< arg value ="/xml=${reports.dir}TestReport-Unit.xml" />
< arg value ="/nologo" />
< arg value ="/noshadow" />
exec >
target >
project >
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/12639172/viewspace-364792/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/12639172/viewspace-364792/
这篇关于【乔梁】用Nant和Nunit构建C#项目的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!