Matt M
Matt M

Reputation: 3779

Can't add migrations to database after migrating .net core

I'm working on a project that was created using a version of dotnet core using a project.json file. I was able to add database migrations and create a database using dotnet ef cli commands in VS Code (add migrations, update, etc.).

However, I've recently migrated the project using the dotnet migrate command, so now my project has a .csproj file. I need to add more database migrations, but when I run the cli commands, I get an error stating the project.json file could not be found.

I've looked at documentation online (and searched the web) and I can't find anything telling me what I might have missed. FWIW, here are the possible relevant packages in my .csproj file:

  <PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.0" />
  <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.0" />
  <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.0" />

    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.1.0-preview4-final" />

Upvotes: 1

Views: 562

Answers (2)

steamrolla
steamrolla

Reputation: 2491

New versions of the tooling were released for the new .csproj way of doing things. You'll need to change your version of Microsoft.EntityFrameworkCore.Tools.DotNet from 1.1.0-preview4-final to 1.0.0-msbuild3-final.

You can see the different latest versions here on Nuget.

Upvotes: 3

Fionn
Fionn

Reputation: 11285

If you don't need the "dotnet ef" tools specifically you can also use the VS Powershell integrated version (Should you need the dotnet ef tools maybe steamrolla's post below can help you):

I use the following package references:

<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.0-preview4-final" />

With these references set, it is possible to use the EF-Tools (Add-Migration, Update-Database, ...) from the Package Manager Console.

Upvotes: 1

Related Questions