Using Microsoft.AspNetCore.Mvc in .NetStandard 1.4 or below class library

666 Views Asked by At

I have requirement to create a .Netstandard library which should support .Net core and .NetFramework 4.5.2. And I must have to use Microsoft.AspNetCore.Mvc in both the targets(.net core app and .NetFramework 4.5.2)

But Microsoft.AspNetCore.Mvc is supported on .Netstandard 1.6 on wards and .Netframework 4.5.1.

I can build .Netstandard 1.6 calss library an consume in .Net 4.5.2. (this is not working below is the problem)

I cannot consume .Netstandard 1.6 from .NetFramework 4.5.2. (I am getting below exception during run Could not load file or assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified)

same question is posted on github too but no solutions yet.(https://github.com/aspnet/Mvc/issues/6028#issuecomment-289606346)

Thanks in advance.

1

There are 1 best solutions below

0
Iain Brown On

You can find the matrix of what versions of .NET standard are supported by which framework here:

https://learn.microsoft.com/en-us/dotnet/articles/standard/library

So no, .net standard 1.6 is not supported by 4.5.2.

Essentially this stuff is still in development, and until .net standard 2.0 is here you'll continue to run into these kinds of issues.

The way we get around this is to build two libs from the same source code, one targeting netcoreapp or .Net standard, the other targeting the full framework. You have two vcproj files, but a single set of code. Not ideal, but the best you can likely do right now.