dfmetro
dfmetro

Reputation: 4592

Cannot add EntityFrameworkCore Tools 1.0.1 to class library in Visual Studio 2017

I am using the latest VS2017 update with donet core 1 I try to create an ef migration to my project with the command dotnet ef but I get

dotnet : No executable found matching command "dotnet-ef"

I then remove any reference to EntityFrameworkCore it from my Class Library csproj (.Net Core) and wanted to add the package Microsoft.EntityFrameworkCore.Tools.DotNet 1.0.1 . However I refuses and I get the following error

Severity Code Description Project File Line Suppression State Error Package 'Microsoft.EntityFrameworkCore.Tools.DotNet 1.0.1' has a package type 'DotnetCliTool' that is not supported by project 'MyVS2017Project'. 0 I also tried it in a Class Library (.Net Framework)

Same error message when using the Package Manager Console command

Install-Package Microsoft.EntityFrameworkCore.Tools.DotNet

I tried editing the csproj file directly and adding

<ItemGroup>
    <DotNetCliToolReference 
     Include="Microsoft.EntityFrameworkCore.Tools.DotNet" 
     Version="1.0.0" />
 </ItemGroup>

but dotnet ef still gives the same error message and nuget package manager doesn't see it

I tried to create a new dot net core class library but even a blank one refuses to install the tools

I have run dotnet restore multiple times and restarted visual studio.

I have downloaded the latest dot net SDK 1.0.4 and run repair to reinstall it. This allows nuget package to install but despite but whatever I do I cannot get the class library to understand dotnet ef

Upvotes: 1

Views: 3815

Answers (2)

Todd Skelton
Todd Skelton

Reputation: 7239

Microsoft.EntityFrameworkCore.Tools.DotNet needs to be added to you class library by editing the project. That is the only way adding it is supported right now. Right click the project and select Edit *.csproj. Then, add the following:

  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0-preview2-final" />
  </ItemGroup>

Note: the version is the latest at the time of this post and will likely change in the future.

I have a more in-depth solution here: EF 7 Migrations with multiple DBContexts

Upvotes: 1

dfmetro
dfmetro

Reputation: 4592

My project targets the full .NET framework, so I can only use the PowerShell commands e.g. add-migration, update-database and not the dotnet ef commands

Upvotes: 3

Related Questions