溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

怎么用Nant和Nunit構(gòu)建C#代碼

發(fā)布時間:2021-07-15 13:51:21 來源:億速云 閱讀:141 作者:chen 欄目:編程語言

這篇文章主要講解了“怎么用Nant和Nunit構(gòu)建C#代碼”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“怎么用Nant和Nunit構(gòu)建C#代碼”吧!

以前沒使用Nant和Nunit構(gòu)建C#代碼的自動化構(gòu)建,今天自己寫了一個C#程序,想用Nant和Nunit構(gòu)建C#代碼??蓪懞胋uild文件后運(yùn)行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開始菜單用運(yùn)行VS所帶的Visual Studio 2005 Command Prompt。

2、切換到nunit的bin目錄下

3、順序運(yùn)行下列命令
gacutil /i nunit.core.dll
// 注冊core

gacutil /i nunit.framework.dll
//注冊framework

gacutil /l
//查看是否注冊上

三、大功告成。

現(xiàn)在運(yùn)行 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構(gòu)建C#代碼”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對怎么用Nant和Nunit構(gòu)建C#代碼這一問題有了更深刻的體會,具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識點(diǎn)的文章,歡迎關(guān)注!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI