user10843855
user10843855

Reputation:

AspNetCore.Mvc.Core Version Mismatch

I'm attempting to write a unit test for a Controller extension method, but during the Test project's build process I receive the following error message.

MyControllerExtensionsTests.cs(17, 26): [CS1705] Assembly 'MyApp.RestApi' with identity 'MyApp.RestApi, 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'

Both projects declare <TargetFramework>netcoreapp2.1</TargetFramework> in their .csproj files. I've tried deleting bin and obj folders. How is one project resolving to Mvc.Core, Version=2.1.0.0 and another Mvc.Core, Version 2.1.1.0?

Upvotes: 8

Views: 3454

Answers (2)

Naren
Naren

Reputation: 827

Update

The issue noted below has been fixed & you should be able to benefit from implicit package versioning and reference like below without providing the version number of the package.

<PackageReference Include="Microsoft.AspNetCore.App" />

Original Answer

This issue is because of the Implicit Versioning that was introduced for Microsoft.AspNetCore.App metapackage. With implicit versioning the sdk decides the version & it resolved it as 2.1.1

However, it was resolving to version 2.1 for the nunit test project. Specifying the version number for the nunit project like <PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.1"/> and performing dotnet restore helped resolve this issue.

There is a ticket for this issue in github and this behavior around implicit versioning could change in future - https://github.com/aspnet/AspNetCore.Docs/issues/6430 & https://github.com/dotnet/core/blob/master/release-notes/1.0/sdk/1.0-rc3-implicit-package-refs.md

Upvotes: 6

Fish
Fish

Reputation: 459

<PackageReference Include="Microsoft.AspNetCore.App" />

I had the same issue, after add this line to unit test project, it start pick right version of Microsoft.AspNetCore.App.

Upvotes: 23

Related Questions