I want to Migrate my Database with Models. I am using EF Core 2.0 Preview.
dotnet ef migrations add InitialCreate
dotnet : No executable found matching command "dotnet-ef"
I am already added all CLI and PM but still got error!
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0-preview2-final" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="2.0.0-preview2-final" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.0-preview2-final" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="2.0.0-preview1-final" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0-preview2-final" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0-preview1-final" />
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0-preview1-final" />
</ItemGroup>
EF Core version: 2.0 Preview
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 10 15063.0
IDE: Visual Studio 2017 Preview
Ensure...
dotnet restore
on the projectcd
ed to the project's (*.csproj
) directoryYes, i am using 2.0 SDK and tried for dotnet restored on project but still got same error.
I am uploaded entire solution on github. CodeFirst is a project, which i want to Migrate and generate error.
https://github.com/mehtanilay10/EntityFrameworkCore
Align your package versions.
Either use preview1 packages or preview2. Mix of those are not supported.
Also to use dotnet ef
correctly, you need to install Microsoft.EntityFrameworkCore.Design
package.
Added Microsoft.EntityFrameworkCore.Design
and also change all to packages to preview1 still facing same error!
Does running dotnet build
pass?
yes, project build successfully. But gives only error for CLI
...and you're certain dir
lists your *.csproj
and dotnet --info
says 2.0.0?
(I know these are stupid questions, but I honestly have no idea what could be going wrong.)
You may need to follow up on dotnet/cli. Something is going wrong before the EF code gets a chance to run.
```PM> dotnet --info
.NET Command Line Tools (2.0.0-preview1-005977)
Product Information:
Version: 2.0.0-preview1-005977
Commit SHA-1 hash: 414cab8a0b
Runtime Environment:
OS Name: Windows
OS Version: 10.0.15063
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Filesdotnet\sdk\2.0.0-preview1-005977\
Microsoft .NET Core Shared Framework Host
Version : 2.0.0-preview1-002111-00
Build : 1ff021936263d492539399688f46fd3827169983
```
If you want to check on my machine then i will give remote access, so you can see what's going wrong.
I cloned the repo posted.
Updated the CodeFirst.csproj
as follows.
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<MvcRazorCompileOnPublish>true</MvcRazorCompileOnPublish>
<UserSecretsId>aspnet-CodeFirst-DB7142CA-3EB8-4FB3-9C4A-0173586B87FB</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0-preview1-final" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="2.0.0-preview1-final" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.0-preview1-final" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="2.0.0-preview1-final" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0-preview1-final" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0-preview1-final" />
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0-preview1-final" />
</ItemGroup>
</Project>
In the directory D:\EntityFrameworkCore\EntityFramework\CodeFirst
dotnet restore
dotnet ef
and it worked.
I had to remove PackageTargetFallback due to this https://github.com/NuGet/NuGet.Client/pull/1495 and I could not find where AssetTargetFallBack is set.
@smitpatel Thanks a lot for solving this issue ;)
Finally it was removed error from CMD but when i am using package manager in VS 2017 15.3 it gives same error. May be this is VS's Issue.
By default Package Manager Console (PMC) is rooted at dir containing the solution file.
dotnet ef
requires to be operated in directory containing csproj
file. The only way to invoke dotnet ef
in PMC, you need to manually cd into the correct folder where your csproj file is located. Changing anything else in PMC has no effect current directory.
For best user experience, use PMC commands for EF (Add-Migration & friends) in PMC.
I has this issue and like to share.
i had the Microsoft.EntityFrameworkCore.Tools.DotNet
as <PackageReference>
because i uesd the GUI package manager to install it.
when i changed it to <DotNetCliToolReference>
and then dotnet restore
, this fixed it.
eg Use:
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
Not
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
That last thing worked for me
In my case i had to change both \library-management\LibraryData\LibraryData.csproj and \library-management\Library\Library.csproj from
My God, this library mangement is from github, orginally a core 1.1 web app I hope realy with 2.0 and webpack things will be stable and change too much.
This worked for me:
The EF tools for the CLI are provided in Microsoft.EntityFrameworkCore.Tools.DotNet. To install this package, add it to the DotNetCliToolReference collection in the .csproj file, You have to install this package by editing the .csproj file; you can't use the install-package command or the package manager GUI. You can edit the .csproj file by right-clicking the project name in Solution Explorer and selecting Edit XXX.csproj.
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
</ItemGroup>
I hade the some trouble and I fix this change the Microsoft.EntityFramework.Tools.Dotnet from the First <ItemGroup>
like this:
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
For a second <ItemGroup>
tag represent the DotNetCliToolReference:
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
It's a pity for new one(.net core user).
dotnet : 未找到与命令“dotnet-ef”匹配的可执行文件
.NET 命令行工具 (2.0.3)
Product Information:
Version: 2.0.3
Commit SHA-1 hash: 12f0c7efcc
Runtime Environment:
OS Name: Windows
OS Version: 10.0.15063
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\2.0.3\
Microsoft .NET Core Shared Framework Host
Version : 2.0.3
Build : a9190d4a75f4a982ae4b4fa8d1a24526566c69df
in powershell dotnet ef
throw new exception:
Could not load type 'Microsoft.EntityFrameworkCore.Infrastructure.DesignTimeProviderServicesAttribute' from assembly 'Microsoft.EntityFrameworkCore, Version=2.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
Is there is a simple way to use this commands or have a good tutorial?
I have just started playing with .Net Core. I am running into issues with
dotnet ef migrations add Initial. I am using Docker for sql server but when I run the command I get following error: Specify which project file to use because this contains more than one project file.
When I remove docker-compose.dcproj, it runs fine but sql server migration generates exception as it doesn't get docker to instantiate DataContext.
On contrary, if I remove *.csproj, it says no executable found matching command.
Need help!
Stack trace as below:
An error occurred while calling method 'BuildWebHost' on class 'Program'. Continuing without the application service provider. Error: Cannot resolve scoped service 'SportsStore.Models.DataContext' from root provider.
No application service provider was found.
Finding DbContext classes in the project...
Found DbContext 'DataContext'.
Microsoft.EntityFrameworkCore.Design.OperationException: Unable to create an object of type 'DataContext'. Add an implementation of 'IDesignTimeDbContextFactory
@amazingankur Where you able to solve your problem? In any case you still have issues with IDesignTimeDbContextFactory, make sure your DataContext class has a default constructor with no parameters in it. The migration script uses the parameterless constructor during execution.
I experienced this issue as well
Just like what @AliBayatGH @veneMarcos @timpur mentioned it appears as if the
dotnet add package Microsoft.EntityFrameworkCore.Tools.DotNet
command is adding the package as a PackageReference to the 2nd Item group in *.csproj. When this package is moved to the 3rd item group and the tag changed to "DotNetCliToolReference" the problem is solved.
To those who may stumble this page looking for answers I have provided codes here in github that can be cloned: https://github.com/jlenriquez/SpikeSQLiteEF_OSX
The sample code can be run step-by-step by commenting/uncommenting necessary steps and can be used as learning reference.
The EF Core .NET Command-line Tools docs may also be helpful.
I fixed this by adding this to my <Project Name>.csproj
file
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" />
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
</ItemGroup>
This line was already there, <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" />
. I only added the second line.
After that then restore the packages by running dotnet restore
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.2" />
</ItemGroup>
I followed this thread and am getting the following
Unable to resolve service for type 'Microsoft.EntityFrameworkCore.Scaffolding.IScaffoldingProviderCodeGenerator' while attempting to activate 'Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpDbContextGenerator'.
Any thoughts?
@ravensorb - You are mixing packages from 2.0 & 2.1 release. Please make sure all packages from EF Core are on same release cycle include EFCore.Tools
This is how I feel about having to install multiple NuGet packages and then manually modify my project configuration file to get the EF toolset, only usable by console, with no UI integration within Visual Studio.
Go to the folder where .csproj is and run “dotnet restore" first
Expliciting changing to my csproj folder and running "dotnet restore" worked for me. First i confirmed if my PackageReference and DotNetCliToolReference were correct, i had two add two missing references. Thks
you might miss the CliToolReference references:
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" />
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" /></ItemGroup>
I have done something worked for me:
1- First dotnet publish your app.
2- Change the execute permission on the .dll in my case I have done: chmod 777 filename.dll
3- Use nano to remove the .sh script \n\r from all the lines.
It should work or might work :)
After adding this :
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.2" />
</ItemGroup>
It works !
clintm@clint ~/l/Librum> dotnet ef
_/\__
---==/ \\
___ ___ |. \|\
| __|| __| | ) \\\
| _| | _| \_/ | //|\\
|___||_| / \\\/\\
Entity Framework Core .NET Command Line Tools 2.0.0-rtm-26452
My problem was that my dotnet
executable was the 3.0.0-preview version, but the EF project that had the design package installed in it was 2.2. So, I dropped a global.json
into the solution root to force 2.2 and then dotnet ef
worked from the root of the solution. I didn't even need to be in the project that had the NuGet package.
@oising was the answer for me, using 3.0.0-preview but creating 2.2 projects.
dotnet new globaljson --sdk-version 2.2.204
I'm using the newly released .NET Core 3.0 with packages in the CSPROJ all being 3.0 but dotnet ef
doesn't work for me.
Edit: to @bricelam's answer below, I found documentation for this in https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/dotnet#ef-core-3x.
dotnet tool install -g dotnet-ef
Also to use
dotnet ef
correctly, you need to installMicrosoft.EntityFrameworkCore.Design
package.
I have that and all above and still have no dotnet ef option when I do dotnet -h and get same error when I issue dotnet ef
dotnet tool install -g dotnet-ef
None of the above worked. Here is my proj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\OdeToFoodCore.Core\OdeToFoodCore.Core.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.1.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.1.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.1.4">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
</Project>
after I run dotnet tool install -g dotnet-ef
, like:
dinob @ /Users/dinob/Desktop/mywork/csharp/aspcore/OdeToFoodCore/OdeToFoodCore.Data
~~ dotnet tool install -g dotnet-ef
You can invoke the tool using the following command: dotnet-ef
Tool 'dotnet-ef' (version '3.0.0') was successfully installed.
I still see no ef tool when I run dotnet -h
dinob @ /Users/dinob/Desktop/mywork/csharp/aspcore/OdeToFoodCore/OdeToFoodCore.Data
~~ dotnet -h
.NET Core SDK (3.0.100)
Usage: dotnet [runtime-options] [path-to-application] [arguments]
Execute a .NET Core application.
runtime-options:
--additionalprobingpath <path> Path containing probing policy and assemblies to probe for.
--additional-deps <path> Path to additional deps.json file.
--fx-version <version> Version of the installed Shared Framework to use to run the application.
--roll-forward <setting> Roll forward to framework version (LatestPatch, Minor, LatestMinor, Major, LatestMajor, Disable).
path-to-application:
The path to an application .dll file to execute.
Usage: dotnet [sdk-options] [command] [command-options] [arguments]
Execute a .NET Core SDK command.
sdk-options:
-d|--diagnostics Enable diagnostic output.
-h|--help Show command line help.
--info Display .NET Core information.
--list-runtimes Display the installed runtimes.
--list-sdks Display the installed SDKs.
--version Display .NET Core SDK version in use.
SDK commands:
add Add a package or reference to a .NET project.
build Build a .NET project.
build-server Interact with servers started by a build.
clean Clean build outputs of a .NET project.
help Show command line help.
list List project references of a .NET project.
msbuild Run Microsoft Build Engine (MSBuild) commands.
new Create a new .NET project or file.
nuget Provides additional NuGet commands.
pack Create a NuGet package.
publish Publish a .NET project for deployment.
remove Remove a package or reference from a .NET project.
restore Restore dependencies specified in a .NET project.
run Build and run a .NET project output.
sln Modify Visual Studio solution files.
store Store the specified assemblies in the runtime package store.
test Run unit tests using the test runner specified in a .NET project.
tool Install or manage tools that extend the .NET experience.
vstest Run Microsoft Test Engine (VSTest) commands.
Additional commands from bundled tools:
dev-certs Create and manage development certificates.
fsi Start F# Interactive / execute F# scripts.
sql-cache SQL Server cache command-line tools.
user-secrets Manage development user secrets.
watch Start a file watcher that runs a command when files change.
Run 'dotnet [command] --help' for more information on a command.
However, issuing dotnet ef shows the screen
dinob @ /Users/dinob/Desktop/mywork/csharp/aspcore/OdeToFoodCore/OdeToFoodCore.Data
~~ dotnet ef
_/\__
---==/ \\
___ ___ |. \|\
| __|| __| | ) \\\
| _| | _| \_/ | //|\\
|___||_| / \\\/\\
Entity Framework Core .NET Command-line Tools 3.0.0
Usage: dotnet ef [options] [command]
Options:
--version Show version information
-h|--help Show help information
-v|--verbose Show verbose output.
--no-color Don't colorize output.
--prefix-output Prefix output with level.
Commands:
database Commands to manage the database.
dbcontext Commands to manage DbContext types.
migrations Commands to manage migrations.
Use "dotnet ef [command] --help" for more information about a command.
Having said that, I am not sure this is good solution, shouldn't ef tool be in project folder version rather than global version?
@dinob68 - I am not able to understand why would dotnet -h
would show anything EF specific.
dotnet tool list
will show the tools you’ve installed
@dinob68 Think of it like a test runner. You don’t need to use an exact version of the runner or use a specific version of the testing framework. One runner will work with multiple versions of the test framework, and more than one version of the runner can be used with the same framework.
dotnet tool install -g dotnet-ef
This worked for me, thanks.
Most helpful comment
I has this issue and like to share.
i had the
Microsoft.EntityFrameworkCore.Tools.DotNet
as<PackageReference>
because i uesd the GUI package manager to install it.when i changed it to
<DotNetCliToolReference>
and thendotnet restore
, this fixed it.eg Use:
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
Not
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />