2016-04-14 189 views
0

我正在關注NUnit教程here「nunit.framework.dll」找不到

我的源文件居住在文件夾C:\Users\Me\Documents\Visual Studio 2015\Projects\NUnitTest\NUnitTest。我的NUnit DLL位於文件夾C:\Program Files (x86)\NUnit.org\framework\3.2.0.0\portable\nunit.framework.dll中。我確信這些路徑是正確的。

編譯源文件AccountTest.cs成一個DLL,我跑以下命令:

cd C:\Users\Me\Documents\Visual Studio 2015\Projects\NUnitTest\NUnitTest 
C:\Users\Me\Documents\Visual Studio 2015\Projects\NUnitTest\NUnitTest>csc /target:library /out:AccountTest.DLL /r:C:\Program Files (x86)\NUnit.org\framework\3.2.0.0\portable\nunit.framework.dll AccountTest.cs 

但是,我看到這些錯誤消息:

error CS2001: Source file 'C:\Users\Me\Documents\Visual Studio 2015\Projects\N 
UnitTest\NUnitTest\Files' could not be found. 
error CS2001: Source file 'C:\Users\Me\Documents\Visual Studio 2015\Projects\N 
UnitTest\NUnitTest\(x86)\NUnit.org\framework\3.2.0.0\portable\nunit.framework.dl 
l' could not be found. 

有什麼建議?

編輯:我沒有忘記在我的解決方案中添加對NUnit的引用。我還包括了適當的using聲明。

+0

你添加了什麼版本的NUnit? – Valentin

+0

版本3.2.0.0。 –

回答

2

這是因爲你從命令行編譯時沒有引用NUnit程序集的路徑。應該是這樣的,

csc /target:library /out:AccountTest.DLL /r:"C:\Program Files (x86)\NUnit.org\framework\3.2.0.0\portable\nunit.framework.dll" AccountTest.cs 

您還應該知道,NUnit控制檯目前無法使用該框架的可移植版本運行測試。爲此,您需要使用NUnitLite創建一個自動執行的測試程序集。目前,僅僅使用.NET 4.5版本的框架會更容易。

你有什麼理由在命令行編譯? Visual Studio Community Edition是免費的,將爲您處理編譯。如果您不在Windows上,MonoDevelop是另一個不錯的選擇。

0

您是否添加了對解決方案的參考?

右鍵單擊解決方案 懸停在添加 點擊參考 搜索NUnit的參考,並將其添加

此外,請確保你已經在你的項目的頂層上的所有類添加using語句

+0

我已經完成了兩個,所以這不是問題:-( –