Setting up TeamCity 5.0.1 to run unit tests for the first time, we're seeing this error:
Test(s) failed. System.IO.FileNotFoundException : Could not load file or assembly 'Moq, Version=3.1.416.3, Culture=neutral, PublicKeyToken=69f491c39445e920' or one of its dependencies. The system cannot find the file specified.
We're using version 3.1.416.3 of Mo开发者_JAVA技巧q, the dll of which has a file version of 3.1.0.0
The reference in our project file looks like this:
<Reference Include="Moq, Version=3.1.416.3, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> <HintPath>..\..\..\lib\binaries\thirdparty\Moq.dll</HintPath> </Reference>
We're able to run our unit tests in Visual Studion with ReSharper, and also from the nunit GUI (both on our developer machines and the build server in question).
What's going on here?
This can be caused by NuGet dependencies. If you do a Rebuild All of your project you may see an innocuous warning when your unit test project is compiled, like this:
Consider app.config remapping of assembly "Moq, Culture=neutral, PublicKeyToken=69f491c39445e920" from Version "4.0.10827.0" [] to Version "4.1.1309.1617" [C:\XXX\packages\Moq.4.1.1309.1617\lib\net40\Moq.dll] to solve conflict and get rid of warning.
This warning may not stop the unit tests running on your local machine, but they may well stop TeamCity from running them.
You can get rid of the warning and make TeamCity run your unit tests by adding something like this to the App.config file for your Unit Test assembly;
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Moq" publicKeyToken="69f491c39445e920" culture="neutral" />
<bindingRedirect oldVersion="4.0.10827.0" newVersion="4.1.1309.1617" />
</dependentAssembly>
</assemblyBinding>
</runtime>
...of course using the appropriate version numbers that you are getting errors about and the actual installed version.
Not a 100% answer, but a workaround:
You can remove the explicit version-number in the build-file. Since it's anyway provided by your project and only used for the tests. Just change the 'Moq, Version=3.1.416.3, ...' part to 'Moq'. Then the version of the hint-path is used.
精彩评论