Visual Studio Mac Preview Entity Framework SQLite Adds Migration

Today I installed Visual Studio for Mac (OSX 10.12.1), and I was pretty active in diving.

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

So, I created a new console Application.NET Core and with some problems I was able to add all the necessary nuget packages. Somehow, Visual Studio was not able to load the dependencies, so I had to load each dependency manually. (Perhaps this solves the problem: .Net Core 1.1.0. NuGet packages that cannot be installed in Visual Studio Mac are not yet tested.)

As stated in this article ( https://docs.microsoft.com/en-us/ef/core/get-started/netcore/new-db-sqlite ), I wanted to add a transfer, but I could not find the command line I needed tool in the IDE. Am I missing something here?

Then I continued to use the .NET Core CLI for this manually. console. ( https://www.microsoft.com/net/core#macos ). But when I do dotnet ef migrations add init , I get the following error.

Could not find executable command "dotnet-ef"

Could anyone get this to work successfully?

+5
source share
5 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 link directly to the csproj , 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 can use the dotnet ef migrations add NameOfMigration and dotnet ef database update scripts according to the documentation.

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

Also see the suggestion tip for VS 2017 for Mac:

+9
source

Using VS for Mac, adding the following lines to .csproj does the migration job 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 .csproj from VS.

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

Note. The same trick with v1.0.1 Tools.DotNet does not work, I do not know why.

+2
source

Check if you have this section in the project.json file and add it if it is missing.

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

This is true for EF 1.1, the previous version used Microsoft.EntityFrameworkCore.Tools package

0
source

Without adding this ItemGroup, you cannot add the connection string to the dbcontext screen using cmd, so first add this to your project (Edit.csproj)

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

For me, this solved the problem on macOS, run this on any terminal:

dotnet tool install --global dotnet-ef

0
source

Source: https://habr.com/ru/post/1260464/


All Articles