Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Mac Preview Entity Framework SQLite add migration

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 (https://learn.microsoft.com/en-us/ef/core/get-started/netcore/new-db-sqlite) 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. ( https://www.microsoft.com/net/core#macos). 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?

like image 671
Michael Lopez Avatar asked Dec 18 '22 11:12

Michael Lopez


1 Answers

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:

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

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:

  • https://visualstudio.uservoice.com/forums/563332-visual-studio-for-mac/suggestions/17169425-add-sql-server-integration
  • https://visualstudio.uservoice.com/forums/563332-visual-studio-for-mac/suggestions/17138506-terminal-window
like image 113
miha Avatar answered Dec 29 '22 05:12

miha