aspnet / Tooling

Issue tracker and info on Visual Studio tooling for ASP.NET
Other
258 stars 124 forks source link

VS 2017RC migration (EF 6x/.NET 4.6 reference issue) #1001

Open freshe opened 7 years ago

freshe commented 7 years ago

Not sure if this is the right place for this.

I have a ASP.NET Core web project that references a business layer, that references a data layer. The data layer is a .NET 4.6.2 project with EF 6x. [Web (aspnetcore)] --> [BLL (aspnetcore)] --> [DAL (net46)]

This works fine in VS2015/project.json world.

The VS2017 migration went well without errors. I get this error when running the project.

"InvalidOperationException: No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient' Make sure the provider is registered in the 'entityFramework' section of the application config file"

Installing EF6 in my web project solves the problem but that is obviously not a solution.

Advice is appreciated!

m4ss1m0g commented 7 years ago

The issue is present also on VS2017 RTM

mlorbetske commented 7 years ago

@bricelam this has been fixed for the upcoming release, hasn't it?

bricelam commented 7 years ago

No idea. It sounds like Web.config (or maybe it should be App.config in ASP.NET Core projects) isn't getting loaded at runtime.

bricelam commented 7 years ago

Or it isn't present (which would explain why installing EF6 into the web app makes it work)

freshe commented 7 years ago

The problem is that EntityFramework.SqlServer.dll is not referenced/copied to the bin folder. Which it did prior to VS2017. Thats why it works to nuget in EF to the web project. I don't know if that is a EF issue or a VS issue though.

bricelam commented 7 years ago

That sounds like the classic MSBuild issue that's been plaguing us for years: It doesn't copy transitive dependencies unless they are explicitly referenced in the dependent the assembly. The best way to work around this issue is to use NuGet's new MSBuild PackageReference items instead of packages.config in your DAL project. See their NuGet PackageReference in Visual Studio Project Files article.

freshe commented 7 years ago

Thank you!

"At present, package references are supported in Visual Studio 2017 only, for .NET Core projects, .NET Standard projects".

Replacing my DAL (.NET Framework Class Library) project with a .NET Standard Class Library project and setting TargetFramework to net461 worked. Now using PackageReference instead of packages.config

bricelam commented 7 years ago

From NuGet is now fully integrated into MSBuild:

We are hard at work to bring full PackageReference support to these project types. Our goal is to eventually make PackageReference the default and move away from all other formats.