Reputation: 6852
Im trying to setup a class library project with EF core 2.1 and use this class library from an .NET core api project. When I attempt to reverse engineer my schema into a dbcontext, I get an error complaining about missing EF command.
Class library csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.0" />
</ItemGroup>
</Project>
donet command
dotnet ef dbcontext scaffold "Server=.;Database=MyDb;user id=my-user;password=my-pwd;" Microsoft.EntityFrameworkCore.SqlServer -c LastMileContext -o Data
error:
No executable found matching command "dotnet-ef"
So after reading a few other threads on this, I changed my csproj file to look like this in the ItemGroup section
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.0" />
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
</ItemGroup>
Now the EF command runs and I get my entity classes. My question is WHY do I yet have to manually add something to the csproj file? Is there not another way? Is the recommended way? Seems maybe like I missed a dotnet command step or something?
Also, looks like im not the only one who has ran into these issues https://fpnotebook.wordpress.com/2017/11/12/solution-entity-framework-core-and-net-core-class-libraries-2-0/
Upvotes: 0
Views: 610
Reputation: 4051
Starting from .NET Core SDK 2.1.300 cli supports so called .NET Core Global Tools and there is no need to manually add these tools into your csproj file.
All you need to do just call dotnet tool install -g toolname
similar as in npm
. You can find some information about available tools in this repo.
dotnet ef
is already included in 2.1.300 SDK CLI.
I will suggest you to download and install .NET Core SDK 2.1.300 for this global tools support but still use .NET Core 2.0 if you don't have plans to migrate to .NET Core 2.1.
Upvotes: 2