4
votes

Currently I have a ASPNet.Core web application with 2 nuget packages that reference different versions of the same dll. The web project works fine, but when I add a reference in a Unit Testing project to the Web project, I get this compile error. Something is clearly solving these dll differences because the web project compiles without issue. It's only when I add a reference to the web project to add tests does the below compilation error occur, and only in the unit testing project.

Assembly 'KII.Web' with identity 'KII.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' uses 'Microsoft.Extensions.Options, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' which has a higher version than referenced assembly 'Microsoft.Extensions.Options' with identity 'Microsoft.Extensions.Options, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' KII.UnitTests
C:\Projects\kii\web\src\Tests\KII.UnitTests\Controllers\HomeControllerTest.cs

Additionally, I also have this build error in the Unit Test project.

Assembly 'KII.Web' uses 'Microsoft.AspNetCore.Mvc.ViewFeatures, Version=2.1.1.0, which has a higher version than referenced assembly 'Microsoft.AspNetCore.Mvc.ViewFeatures' with identity 'Microsoft.AspNetCore.Mvc.ViewFeatures, Version=1.0.3.0

Essentially the web project has this

  • Microsoft.AspNetCore.App 2.2.0 has a reference to Microsoft.Extensions.Options 2.2.0
  • KenticoCloud.Delivery 10.0.1 has a reference to Microsoft.Extensions.Options 2.1.1

Things I've tried

  • clean/rebuild
  • manually delete bin directories
  • add binding redirects in app.configs in both unit testing and web projects
  • Update KenticoCloud.Delivery to 11.0.0-beta1

Since this is .net core, there are no hintpaths that I can tweak in the web.config. I don't think checking the GAC for an old version/updating it is going to work because .net core doesn't use the GAC. Since the dll in question is a sub-dependency of nuget packages, I cannot update the nuget packages to resolve.

Similar SO question

1
have you considered downgrading your application to Microsoft.AspNetCore.App 2.1.1 which would eliminate your issue.Patrick Mcvay
@PatrickMcvay doing this resolved the error, but I had 2 dll errors. The other remains. Assembly 'KII.Web' uses 'Microsoft.AspNetCore.Mvc.ViewFeatures, Version=2.1.1.0, which has a higher version than referenced assembly 'Microsoft.AspNetCore.Mvc.ViewFeatures' with identity 'Microsoft.AspNetCore.Mvc.ViewFeatures, Version=1.0.3.0w00ngy

1 Answers

0
votes

The solution to this was to directly install the latest version of the one of the shared package dependencies Microsoft.AspNetCore.Mvc.ViewFeatures version 2.2.0 in the Web project. Adding a direct dependency on this package allowed the unit test project to resolve its dependencies correctly.

Added this package dependency in KII.Web.csproj

<PackageReference Include="Microsoft.AspNetCore.Mvc.ViewFeatures" Version="2.2.0" />