0
votes

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

2
After editing the csproj did you run a dotnet restore?Matt
Yes I did do dotnet restoredfmetro
That package only works with console applications, it does not work with class libraries. Have you tried doing it in a console app? ...or in an asp.net core app, since it is also a console app.gregkalapos
I have always used class libraries with this app. Only since I upgraded to the last Visual Studio update has the whole thing broken. I need to use a class library as I separate my data layer/repository from my front end using class librariesdfmetro
You can have your data layer in a class library, but you cannot run dotnet ef in a class library. See this: github.com/aspnet/EntityFramework/issues/5320. As a test I really would create a console application, move the migrations there and run dotnet ef from there... just to test if that works. If it doesn't then you have a broken setup, if it does, then you are affected by this 'class library limitation'.gregkalapos

2 Answers

2
votes

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

0
votes

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