Visual Studio Mac Preview Entity Framework SQLite add migration

.net-core entity-framework-core macos visual-studio


I've installed Visual Studio for Mac (OSX 10.12.1) today and I've been diving in quite extensively.

I wanted to try to get EntityFrameworkCore (1.1.0) to run with SQLite.

So I've created a new Console Application .NET Core and with some troubles been able to add all the necessary nuget packages. Somehow Visual Studio was not able to download the dependencies, so I had to download every dependency manually. (Maybe this solves the problem: .Net Core 1.1.0 NuGet packages fail to install in Visual Studio Mac haven't testet this yet.)

As stated in this article ( I wanted to add the migration, but I couldn't find the necessary command line tool in the IDE. Did I miss something here?

Then I went on to use the .NET Core CLI to do it manually via. console. ( But when I execute dotnet ef migrations add init I get the following error.

No executable found matching command "dotnet-ef"

Was anyone able to get this to run successfully?

5/23/2017 11:54:59 AM

Accepted Answer

Visual Studio for Mac 2017 currently (April 2017) does not support adding a reference to Microsoft.EntityFrameworkCore.Tools.DotNet and returns an error:

Package 'Microsoft.EntityFrameworkCore.Tools.DotNet 1.0.0' has a package type 'DotnetCliTool' that is not supported by project 'MacMvc'.

You can edit the file manually and add the reference directly to the csproj file, as documented. Add this to your csproj file:

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

Then run dotnet restore to install the package. After that, you will be able to use dotnet ef migrations add NameOfMigration and dotnet ef database update scripts as per documentation.

N.B.: you must be in the project directory when executing commands.

Also see suggestion feeedback for VS 2017 for Mac:

4/25/2017 9:13:10 AM

Popular Answer

Using VS for Mac, adding those following lines into .csproj makes the migration work for me:

<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.1" />
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0-msbuild2-final" />

Packages will be automatically restored saving the .csproj from VS.

To run the "dotnet ef" command through the terminal, you need to be in the project directory, I mean not from the directory where the .sln file is, but from the lower level.

Note: Same trick with v1.0.1 of Tools.DotNet didn't work, I do not know why.

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow