“Could not load file or assembly” when building using team city

主宰稳场 提交于 2019-12-13 11:38:58

问题


I'm running into an issue with unit tests on our Team City (8.0.4) build server - the code builds & runs all tests locally via Resharper and nCrunch.

But when running on the server I get the following error, even though the Unity assembly exists in the same directory as the unit test assembly, and is referenced in the unit test assembly.

SetUp method failed. SetUp : System.IO.FileNotFoundException : Could not load file or assembly 'Microsoft.Practices.Unity, Version=2.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified. at XXXX.Unity.UnityContainerAdapter..ctor() at XXXX.GraphExtensionsTests..ctor() in c:\TeamCityV7\Agent-1\work\f02f7e27c0bedfa2\XXXX\Graph.Tests\Extensions\GraphExtensionsTests.cs:line 44

I've confirmed the copy of Microsoft.Practices.Unity is the correct version.

I've also confirmed the assemblies are built using the full version of the framework - not using client profile.

Any ideas why Team City might be failing?


回答1:


Check the pattern you're using to locate your test assemblies. I had a similar problem with another library and it turns out the pattern was finding the test assembly under bin\Release and obj\Release; the obj folder doesn't contain all the assemblies referenced by the project and is really just a scratch folder for the compiler.




回答2:


Another possibility I recently discovered is if you are using a library that you are not explicitly referencing, TeamCity will not collect the library for use and fail when it is implicitly referencing the assembly. I discovered this when trying to figure out why NHibernate.ByteCode.Castle, which was referenced in my test project, was not being loaded and resulting in a FileNotFoundException on TeamCity. Ultimately, I made a "dummy" unit test like so:

using Microsoft.VisualStudio.TestTools.UnitTesting;
using NHibernate.ByteCode.Castle;

namespace MyNamespace
{
    [TestClass]
    public class CastleProxyPresenceTest
    {

        [TestMethod]
        [TestCategory("Infrastructure: This test forces TeamCity to load the NHibernate.ByteCode.Castle.dll file.")]
        public void CastleProxyLoads()
        {
            var dummy = new LazyFieldInterceptor();
            Assert.IsNotNull(dummy);
        }
    }
}

...after this, the file loaded properly and my unit tests compiled.



来源:https://stackoverflow.com/questions/21164646/could-not-load-file-or-assembly-when-building-using-team-city

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!