Introduction
Where there are multiple project within the solution and one project is dependent on other, and versions introduce breaking changes, we sometimes encounter package version conflict and Visual Studio solution does not build. It may return the following error:
Error CS1705 Assembly 'WebAPI' with identity 'WebAPI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' uses 'Microsoft.AspNetCore.Mvc.Core, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' which has a higher version than referenced assembly 'Microsoft.AspNetCore.Mvc.Core' with identity 'Microsoft.AspNetCore.Mvc.Core, Version=2.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' WebApiTest C:\...
The above error can be produced on a solution that uses two projects, namely WebApi and WebApiTest.
Background
The error above shows that the test project and API project are using a different version of Microsoft.AspNetCore.Mvc.Core. For example, the test project is using version 2.1.0.0 while the API project is using 2.1.1.0.
We can resolve this issue by updating the package reference in either of the projects to match. For example, we can update the WebApiTest project to use the higher version of the assembly (i.e., at 2.1.1.0) or downgrade the assembly version in the WebApi project to 2.1.0.0 depending on the need.
Resolution Example
We can issue a command like below in the package manager console targetting the right project. For example, the code below will update the assembly reference for Microsoft.AspNetCore.Mvc.Core on WebApiTest test to use version 2.1.1.0. This will then match the version of the same assembly in the WebApi project. The following code
Install-Package Microsoft.AspNetCore.Mvc.Core -Version 2.1.1.0 -ProjectName WebApiTest
The argument '- ProjectName WebApiTest' name can be omitted if the correct project is selected in the dropdown that is available in the Package Manager Console window in the Visual Studio. An example of screen shot is shown in the figure below:
Figure: Package Manager Console window in Visual Studio 2017 running on Windows machine.
Likewise, to update the WebApi project instead, the following command will do the trick:
Install-Package Microsoft.AspNetCore.Mvc.Core -Version 2.1.1.0 -ProjectName WebApiTest
History
03/21/2019. Added an image of a package manager console.
03/20/2019. First Commit