Solving ASP.NET MVC assembly versioning problems after NuGet package updates in solutions that use unit tests

Posted: (EET/GMT+2)

 

If you are developing ASP.NET MVC applications, chances are you are using unit tests projects, too. When you have your main project using NuGet packages and using those same assemblies in your unit test projects, you might get into a situation where your builds starts to fail when you update your NuGet packages to their latest versions.

Symptoms in Visual Studio's Error List window look something like this:

Error: Assembly 'MyWebApp, Version=1.3.8.0, Culture=neutral, PublicKeyToken=null' uses
'System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' which
has a higher version than referenced assembly 'System.Web.Mvc, Version=5.1.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35' -- MyWebApp.Tests

Warning: Found conflicts between different versions of the same dependent assembly that
could not be resolved. These reference conflicts are listed in the build log when log
verbosity is set to detailed. -- MyWebApp.Tests

The solution for this problem is as follows:

Take a look at the "Project" field in the Error List window. It usually shows the unit tests project "MyWebApp.Tests". NuGet does not remember to update the versions in unit test projects. You have to do this manually.

Here are the steps:

  1. Remove offending assembly (here, System.Web.Mvc) from the References list of the unit test project.
  2. Add the latest reference to the same assembly; you can find the correct one from the “packages” folder.
  3. Rebuild your solution.

Problem solved!