Search code examples
asp.netasp.net-mvcjenkinsmsbuildmsbuild-4.0

.Net Build server tests fail because a dependancy can't be found


I'm building a Jenkins build server for a .Net application. It's based on ASP.Net MVC 5, and has tests through NUnit.

One of my testing projects Errors out for all the tests on the build server.

1) SetUp Error : project.Test.Area.Test_Name

SetUp : System.IO.FileLoadException : Could not load file or assembly 'System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

at project.Test..Area.SetUp()

All my projects and test projects reference System.Web.Mvc 5.2.3.0, and the testing project doesn't even use the System.Web.Mvc namespace. The System.Web.Mvc namespace is set to copy local, and included in the NuGet package manager.

I'm assuming it might be another dependency, which itself depends on MVC 5.1.0.0, but since my project doesn't depend on that version Jenkins had no reason to fetch it while my local system already has it from other projects.

The various app.config and web.config files also all specify 5.2.3 for MVC.

Is there a way to figure out which dependency is causing the issue, or should I just find a way to install MVC 5.1.0.0 on the build server?


Edit: I found this reference to a transform in Mvc 5.1.2

src\packages\Microsoft.AspNet.Mvc.5.1.2\Content\Web.config.install.xdt:

28        <dependentAssembly xdt:Transform="Insert">
29          <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"  />
30:         <bindingRedirect oldVersion="1.0.0.0-5.1.0.0" newVersion="5.1.0.0" />
31        </dependentAssembly>
32      </assemblyBinding>

Does that look like that transform should be transforming old 5.1.0 versions to 5.1.2.0 and just isn't updating it right?

Edit 2: Nope, changing that doesn't affect anything, and I can't find anywhere else in the project that 5.1.0 is referenced.


Solution

  • Bummer. One hates this kind of thing. Things that I have tried before:

    • Is Visual Studio installed on the build machine and is MVC 5 therefore installed in some silly place like C:\Program Files\Reference Assemblies\Microsoft\Framework\ or C:\Program Files\MSBuild\Microsoft or C:\Program Files\Microsoft.NET or especially:

      C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Stack 5

    where msbuild might find it? Or

    gacutil -l | grep Mvc
    

    (which surprised me: I found MVC 4 on mine).

    • Can you manually run msbuild from the command line on the build machine? If so you can then run with /verbosity:stupidlyhigh sorry I mean /verbosity:detailed and hopefully see the exact line in the msbuild project/target files which is failing?

    Or at least confirm from the command line before running msbuild that the depended assemblies are where you expect them?

    • Or drill down the actual contents of the packages folder on the build machine to confirm that the Microsoft.AspNet.Mvc directory contains the version you expect?

    Note that other packages with a dependency on MVC5 may pull in additional versions from NuGet, which leaves it a bit random as to which gets copied into the bin folder last. You typically resolve this problem with an AssemblyBindingRedirect in your [web|app].config(s).

    • Did someone check any dlls or the bin directory or the NuGet packages directory into TFS 6 months ago? In which case, the dlls will all be checked out readonly, which means they may not be properly overwritten/updated by a build or a Nuget restore.