无法加载文件或程序集'Moq,4.2.1502.911或其依赖项之一

Rah*_*dha 14 unit-testing moq nuget-package visual-studio-2013

我从我的项目的Manage Nuget Packages安装了Moq nuget包.项目构建成功,但是当我运行测试用例时,它会抛出以下错误

System.IO.FileLoadException: Could not load file or assembly 'Moq, Version=4.2.1502.911, Culture=neutral, PublicKeyToken=69f491c39445e920' or one of its dependencies
Run Code Online (Sandbox Code Playgroud)

我检查了项目引用,Moq.dll就在那里.

另外我在测试运行的输出窗口注意到这一点

------ Discover test started ------
Unable to load the test container 'C:\dev\tfs\Main\GUI\Gui.Client\Bin\Debug\Gui.Client.dll' or one of its dependencies. Error details: System.IO.FileNotFoundException: Could not load file or assembly 'System.Windows, Version=5.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. The system cannot find the file specified.
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Practices.Prism, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
System.IO.FileNotFoundException: Could not load file or assembly 'System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. The system cannot find the file specified.

========== Discover test finished: 20 found (0:00:03.4941998) ==========
------ Run test started ------
Warning: conflict during test run deployment: deployment item 'c:\dev\tfs\main\gui\test\gui.client.state.tests\bin\debug\Moq.dll' directly or indirectly referenced by the test container 'c:\dev\tfs\main\gui\test\gui.client.state.tests\bin\debug\gui.client.state.tests.dll' cannot be deployed to 'Moq.dll' because otherwise the file 'c:\dev\tfs\main\gui\test\gui.client.state.tests\bin\debug\Moq.dll' would overwrite deployment item '..\ThirdPartyLibraries\NuGetPackages\Moq.4.2.1402.2112\lib\net40\Moq.dll' specified by the test settings.
Warning: Test Run deployment issue: The assembly or module 'NMath' directly or indirectly referenced by the test container 'c:\dev\tfs\main\gui\test\gui.client.state.tests\bin\debug\gui.client.state.tests.dll' was not found.
========== Run test finished: 1 run (0:00:23.2373118) ==========
Run Code Online (Sandbox Code Playgroud)

小智 9

有同样的问题.更新了所有项目的Moq nugets,他们都使用相同的Moq库,它对我来说很好.

右键单击您的Moq参考,并确保您在任何地方使用相同的版本.如果没有更新使用nuget包管理器