问题
I have a .NET Core 1.0 class library which targets .NET 4.6.1 and references the .NET Standard Library 1.6.0 and Identity Framework 2.2.1
project.json
{
"version": "1.0.0-*",
"dependencies": {
"Microsoft.AspNet.Identity.EntityFramework": "2.2.1",
"System.Runtime": "4.1.0",
"NETStandard.Library": "1.6.0"
},
"frameworks": {
"netstandard1.6": {
"imports": [
"net461"
]
}
}
}
In my project I'm just creating the identity models, which extend the base Identity Framework models (User, Role etc). When I try to compile, this happens...
Any ideas how to resolve this?
回答1:
There are two problems with your project file here, one simple to fix, one impossible to fix ;)
- Your project does not target
net461andnetstandard1.6. What your project.json says is: Build target fornetstandard1.6and lie to NuGet and claim you arenet461(that lying is whatimportdoes ... do not believe me, look it up ;)). And since your project.json lied to NuGet, you where able to addMicrosoft.AspNet.Identity.EntityFramework. Addingnet461andnetstandard1.6in parallel will not help you either because you cannot add the dependency then. - The NuGet dependency
Microsoft.AspNet.Identity.EntityFrameworkis released in 2015 and based on the .NET Framework (mscorlib based) and not on .NET Standard / .NET Core (System.Runtime based). The lying does not help about the fact that the dependency is based onmscorliband notSystem.Runtime.
What you could try, is targeting (correctly) in parallel net461 and netstandard1.6 and try to do a parallel implementation with Microsoft.AspNet.Identity.EntityFramework and Microsoft.AspNetCore.Identity.EntityFrameworkCore respectively using #ifdefs. However, how useful the result would be, I have no idea for what the resulting library would be used ;)
回答2:
Microsoft has a nuget package that can help. I don't know the specifics of how it works but it resolved my dependency issues:
https://www.nuget.org/packages/Microsoft.NETCore.Portable.Compatibility/
Or simply run this in the package manager console:
Install-Package Microsoft.NETCore.Portable.Compatibility -Version 1.0.1
edit: This was added to a .net core 1.1 project.
来源:https://stackoverflow.com/questions/38646466/referencing-mscorlib-4-0-0-0-from-net-core-1-0-class-library