温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

怎么用Nant和Nunit构建C#代码

发布时间:2021-07-15 13:51:21 来源:亿速云 阅读:130 作者:chen 栏目:编程语言

这篇文章主要讲解了“怎么用Nant和Nunit构建C#代码”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“怎么用Nant和Nunit构建C#代码”吧!

以前没使用Nant和Nunit构建C#代码的自动化构建,今天自己写了一个C#程序,想用Nant和Nunit构建C#代码。可写好build文件后运行UnitTest时遇到了麻烦。命令行提示如下:
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)中加入如下代码:

  1. <?xmlversionxmlversion="1.0"encoding="utf-8"?> 

  2. <configuration> 

  3. <runtime> 

  4. <assemblyBindingxmlnsassemblyBindingxmlns="urn:schemas-microsoft-com:asm.v1"> 

  5. <dependentAssembly> 

  6. <assemblyIdentitynameassemblyIdentityname="nunit.framework"
    publicKeyToken="96d09a1eb7f44a77"culture="Neutral"/> 

  7. <bindingRedirectoldVersionbindingRedirectoldVersion="2.0.6.0"newVersion="2.4.3.0"/> 

  8. <bindingRedirectoldVersionbindingRedirectoldVersion="2.1.4.0"newVersion="2.4.3.0"/> 

  9. </dependentAssembly> 

  10. </assemblyBinding> 

  11. </runtime> 

  12. </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
//查看是否注册上

三、大功告成。

现在运行 nant unittest 就完事大吉。

附 nant 的 build 文件如下:

<?xmlversionxmlversion="1.0"?> <projectnameprojectname="CSharpMoney"default="ut"> <propertynamepropertyname="output.dir"value="../bin"/> <propertynamepropertyname="output.dll"value="../bin/cs-money.dll"/> <propertynamepropertyname="reports.dir"value="../reports"/> <targetnametargetname="clean"> <deletedirdeletedir="${output.dir}"/> <deletedirdeletedir="${reports.dir}"/> </target> <targetnametargetname="copyfile"depends="clean"> <mkdirdirmkdirdir="${output.dir}"unless="${directory::exists(output.dir)}"/> <copyfilecopyfile="../nunit/bin/nunit.framework.dll"todir="${output.dir}"  if="${file::exists('nunit/bin/nunit.framework.dll')}"/> </target> <targetnametargetname="build"depends="copyfile"> <csctargetcsctarget="library"output="${output.dll}"debug="true"> <sources> <includenameincludename="*.cs"/> </sources> <references> <includenameincludename="../nunit/bin/nunit.framework.dll"/> </references> </csc> </target> <targetnametargetname="ut"depends="build"> <mkdirdirmkdirdir="${reports.dir}"/> <execprogramexecprogram="..NUnitunit-console.exe"> <argvalueargvalue="${output.dll}"/> <argvalueargvalue="/config=cs-money.dll.config"/> <argvalueargvalue="/xml=${reports.dir}TestReport-Unit.xml"/> <argvalueargvalue="/nologo"/> <argvalueargvalue="/noshadow"/> </exec> </target> </project>

感谢各位的阅读,以上就是“怎么用Nant和Nunit构建C#代码”的内容了,经过本文的学习后,相信大家对怎么用Nant和Nunit构建C#代码这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI