Efcore: Microsoft.EntityFrameworkCore.SqlServer in Class Library - RC2

Created on 17 May 2016  路  20Comments  路  Source: dotnet/efcore

I'm having trouble getting Microsoft.EntityFrameworkCore.SqlServer working within a class library. It is telling me that IX-Async and Remotion.Linq are not compatible with .NETStandard,Version=v1.5.

This is very easy to reproduce. I just installed RC2. Created a new project and chose Class Library (.NET Core). Then installed Microsoft.EntityFrameworkCore.SqlServer rc2 via nuget, and get a compiler error.

Any ideas on how to get around this?

project.json

{
  "version": "1.0.0-*",

  "dependencies": {
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-rc2-final",
    "NETStandard.Library": "1.5.0-rc2-24027"
  },

  "frameworks": {
    "netstandard1.5": {
      "imports": "dnxcore50"
    }
  }
}

Most helpful comment

Imports can be used to allow packages that use .NET Standard to interoperate with packages that were originally built against other targets. We are working with the owners of IX-Async and Remotion.Linq so that they can add .NET Standard support in their packages, after which this workaround should become unnecessary.

All 20 comments

Try changing your imports to look like this:

      "imports": [
        "dnxcore50",
        "portable-net452+win81"
      ]

That worked thank you very much!

What exactly is adding that doing? I'm assuming this is kind of binding me to Windows (which is fine) given that sql server only works on windows.

Imports can be used to allow packages that use .NET Standard to interoperate with packages that were originally built against other targets. We are working with the owners of IX-Async and Remotion.Linq so that they can add .NET Standard support in their packages, after which this workaround should become unnecessary.

sql server only works on windows

Not really :smile: The .NET Core version of System.Data.SqlClient works cross-platform and even SQL Server on Linux is coming https://www.microsoft.com/en-us/server-cloud/sql-server-on-linux.aspx

@divega You should probably mention this import thing in the upgrading manual.

@gdoron - @natemcmaster added some info to that article.

Hi ,

I am trying to upgrade my project to RC2.
In my previous project.json, i was able to refer gac assemblies using the frameworkassemblies section. But after upgrading to RC2, assemblies in gac are not getting recognized.
Even i tried using the import , but no luck.

Can anyone help me ?

sample project.json :
"frameworks": {
"net451": {
"imports": [ "portable-net452+win81" ],
"frameworkAssemblies": {
"gac-assmebly_name ": {
"version": "1.4.4.4",
"type": "build",
},
I am getting the below error
The dependency gac-assmebly_name >= 1.4.4.4 could not be resolved .

I have verified that the assembly is present in the GAC.

GAC assembly references are not supported in the .NET CLI. File an issue here https://github.com/dotnet/cli

we have an assembly which because of various dependencies, can not be created as package.
So what is the work around or alternative to referring the assembly present in GAC ?

You can't reference it from the GAC for compilation so you'd need to put it in a nuget package

@davidfowl As of now nuget package is not possible, do have any other way to do it ?

Thanx @divega sir for your post of import to use entity framework in class library

Now i m facing the problem
Microsoft.EntityFrameworkCore.Tools in class library

This preview of Entity Framework tools does not support targeting class library projects in ASP.NET Core and .NET Core applications.
Need Help

I had the same issue, I found that the name had been changed,
"Microsoft.EntityFrameworkCore.Tools.Core": "1.0.0-rc2-final",

instead of the original EntityFrameworkCore.Tools

@ermithun "Microsoft.EntityFrameworkCore.Tools" does not support .NET Core class libraries. See https://github.com/aspnet/EntityFramework/issues/5320.

@ofer the class library was in RC1 EntityFramework.Commands and we renamed it to Microsoft.EntityFrameworkCore.Tools version "1.0.0-preview1-final" for RC2. See https://docs.efproject.net/en/latest/miscellaneous/rc1-rc2-upgrade.html#package-names-and-versions

What is the relationship between Microsoft.EntityFrameworkCore.Tools.Core and Microsoft.EntityFrameworkCore.Tools
Are they different libraries or does one supersede the other?
Is the documentation found here current and correct: https://docs.efproject.net/en/latest/miscellaneous/rc1-rc2-upgrade.html#package-names-and-versions

@sam-wheat Microsoft.EntityFrameworkCore.Tools is the package you should install. Microsoft.EntityFrameworkCore.Tools.Core is some infrastructure used by the tooling and is a dependency of the other package.

@rowanmiller Hi, I am using EF Core Code First, and I am trying to move my DbContext in separate class library. But the problem is I cannot Add-Migrations there. When I try to install Microsoft.EntityFrameworkCore.Tools it says "The dependency Microsoft.EntityFrameworkCore.Tools 1.0.0-preview1-final does not support framework .NETStandard, Version=v1.5".
This is my project.json to the class library:
`{
"version": "1.0.0-*",

"dependencies": {
"NETStandard.Library": "1.5.0-rc2-24027",
"Npgsql.EntityFrameworkCore.PostgreSQL": "1.0.0-rc2-release1",
"Microsoft.EntityFrameworkCore": "1.0.0-rc2-final",
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview1-final", ---> shows error
},

"tools": {
"Microsoft.EntityFrameworkCore.Tools": {
"version": "1.0.0-preview1-final",
"imports": [
"portable-net452win81+dnxcore50",
"portable-net452+win81"
]
}
},

"frameworks": {
  "netstandard1.5": {
    "imports": [
      "dnxcore50",
      "portable-net452+win81"
    ]
  }
}

}`

"But the problem is I cannot Add-Migrations there. "
I hope this one is fixed or high on the to-do list.

See also: http://benjii.me/2016/05/dotnet-ef-migrations-for-asp-net-core/

@dbrezoev @sam-wheat you are hitting https://github.com/aspnet/EntityFramework/issues/5320, there are details of workarounds etc. at https://docs.efproject.net/en/latest/cli/dotnet.html#targeting-class-library-projects-is-not-supported

Was this page helpful?
0 / 5 - 0 ratings