2

I am trying to learn the basics of ASP.NET Core using this tutorial:

  1. I have created a ASP.NET Core web application
  2. I have upgraded it using instruction from here

Now, I am trying to setup the database migration using dotnet ef migrations add Initial from command prompt within project's folder (where project.json is located):

No executable found matching command "dotnet-ef"

I have changed project.json, so that dotnet-ef works:

"tools": {
...
"Microsoft.EntityFrameworkCore.Tools": {
  "version": "1.0.0-preview1-final",                
  "imports": [
    "portable-net45+win8+dnxcore50",
    "portable-net45+win8"
  ]
}

Now, the generation fails with the following error:

The specified framework 'Microsoft.NETCore.App', version '1.0.0-rc2-3002702' was not found. - Check application dependencies and target a framework version installed at: C:\Program Files\dotnet\shared\Microsoft.NETCore.App - The following versions are installed: 1.0.0 1.0.1 1.1.0 - Alternatively, install the framework version '1.0.0-rc2-3002702'

Ok, it makes sense, because Microsoft.EntityFrameworkCore.Tools 1.0.0-preview1-final relies on the old version mentioned in the error, as found in the project.lock.json file.

I don't want to downgrade, so I put the latest version of Microsoft.EntityFrameworkCore.Tools I could find:

 "Microsoft.EntityFrameworkCore.Tools": {
  "version": "1.1.0-preview4-final",
  "imports": [
    "portable-net45+win8+dnxcore50",
    "portable-net45+win8"
  ]
},

Doing this will lead to the same error:

No executable found matching command "dotnet-ef"

How can I make it work in version 1.1?

Other context information that might be useful:

OS: Windows 7 x64 VS: 2015 Community Edition Other parts from project.json:

"frameworks": {
"netcoreapp1.1": {
  "imports": [
    "portable-net45+win8+dnxcore50",
    "portable-net45+win8"
  ]
}
},

"runtimes": {
"win7-x64": {}
},
2

5 Answers 5

6

UPDATE [30/3/2017]

The new package is

Install-Package Microsoft.EntityFrameworkCore.Tools

ORIGINAL

Try adding

"tools": {
    "Microsoft.EntityFrameworkCore.Tools.DotNet": "1.1.0-preview4"
  }

Additionally here is a tutorial on setting up .Net Core 1.1.0 with EF Core 1.1.0

https://learn.microsoft.com/en-us/ef/core/get-started/netcore/new-db-sqlite

1
  • It worked. I also lacked "Microsoft.EntityFrameworkCore.Tools": { "version": "1.1.0-preview4-final" Dec 4, 2016 at 7:18
1

Grierson's answer is ok, but for future reference I will include the whole process until I made it work:

1) Tools.DotNet already suggested in the accepted answer

"tools": {
    "Microsoft.EntityFrameworkCore.Tools.DotNet": "1.1.0-preview4"
  }

Ran the same command and received:

Cannot execute this command because Microsoft.EntityFrameworkCore.Design is not installed. Install the version of that package that matches the installed version of Microsoft.EntityFrameworkCore and try again.

2) Added

//EF Core
"Microsoft.EntityFrameworkCore.Tools": {
  "version": "1.1.0-preview4-final",
  "type": "build"
}

3) Now, the error is:

No parameterless constructor was found on 'ApplicationDbContext'. Either add a parameterless constructor to 'Application DbContext' or add an implementation of 'IDbContextFactory' in the same assembly as 'ApplicationDbC ontext'.

I have chosen to implement the interface. One possible way:

public ApplicationDbContext Create(DbContextFactoryOptions options)
{
    var builder = new DbContextOptionsBuilder<ApplicationDbContext>();
    builder.UseSqlServer("Server=(localdb)\\mssqllocaldb;Database=Movies;Trusted_Connection=True;MultipleActiveResultSets=true");
    return new ApplicationDbContext(builder.Options);
}

The same error occurs when running dotnet ef migrations add Initial

4) I have added a default constructor for ApplicationDbContext class

Now I can add the migration.

0

EntityFrameworkCore 1.1.0-preview4-final will work only asp.net core 1.1,if you want to move from core 1.0 to core 1.1,look into https://blogs.msdn.microsoft.com/dotnet/2016/11/16/announcing-net-core-1-1/.

0

I had the same issue.

that's resolved it for me

"tools": {
"Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final",
"Microsoft.EntityFrameworkCore.Tools.DotNet": "1.1.0-preview4-final"
},
0

You might miss CliToolReference

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

check this

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.