Search code examples
.netentity-framework-corenpgsqlmacos-sierra

Npgsql EF Core Provider v2.0: Can't reverse-engineer a core model from existing database


Development environment:

  • macOS Sierra Version 10.12.6
  • Visual Studio Community for Mac Version 7.2.2
  • postgreSQL Version 9.4.5
  • Npgsql.EntityFrameworkCore.PostgreSQL Version 2.0.0 (Npgsql 3.2.5)

Refer to http://www.npgsql.org/efcore/index.html

Here's the .csproj contents:

    <Project Sdk="Microsoft.NET.Sdk.Web">
    <PropertyGroup>
        <TargetFramework>netcoreapp2.0</TargetFramework>
    </PropertyGroup>
    <ItemGroup>
        <Folder Include="wwwroot\" />
        <Folder Include="SQL Scripts\" />
        <Folder Include="Models\" />
    </ItemGroup>
    <ItemGroup>
        <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
        <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
        <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.0.0" />
        <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.0" />
        <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.Design" Version="2.0.0-preview1" />
    </ItemGroup>
    <ItemGroup>
        <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
    </ItemGroup>
</Project>

From the .csproj contents, note the version of "Npgsql.EntityFrameworkCore.PostgreSQL.Design". It is "2.0.0-preview1". There was no nuget package for "2.0.0".

When I attempt to issue a command to reverse-engineer an existing postgreSQL database, I encounter the following message:

Version for package `Microsoft.VisualStudio.Web.CodeGeneration.Tools` could not be resolved.

Here's the sanitized command line I used to reverse-engineer the existing database:

dotnet ef dbcontext scaffold "Host=localhost;Database=mydatabase;Username=me;Password=mypwd" Npgsql.EntityFrameworkCore.PostgreSQL

The version of the Microsoft.VisualStudio.Web.CodeGeneration.Tools package is version 2.0.0.

My NuGet settings are as follows:


Solution

  • A few notes:

    1. There is no Npgsql.EntityFrameworkCore.PostgreSQL.Design because that package was merged into the main package in the 2.0.0 release. You should remove that dependency.
    2. The Microsoft.VisualStudio.Web.CodeGeneration.Tools has nothing to do with Entity Framework - it's an ASP.NET web-related command. I'm not sure why you're getting an error, trying temporarily removing that dependency to see what happens.
    3. Command-line scaffolding is available via the Microsoft.EntityFrameworkCore.Tools.DotNet package, which you don't seem to be referencing. See this page for help and the other EF Core tutorials.