1
votes

I have created a .net core web app targeting the full .net framework

I Have created a class library (.net framework) In this dll I have referenced ef core and created a context. Migrations work when I use the package manager.

The Problem I am currently facing I need to be able to use migrations during a VSTS deployment.

I have tried creating a powershell deployment script in VSTS to call dotnet-ef commands. This doesn't work, because I can't install Microsoft.EntityFrameworkCore.Tools.DotNet in my projects

I have tried to add the reference manually in my .csproj Manual update .csproj

But unfortunately this doesn't solve my problem and only produces this result. Faulty reference

2
What if you change the ItemGroup as <ItemGroup> <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.0" /> <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0" /> </ItemGroup> similar as setting in this article docs.microsoft.com/en-us/aspnet/core/data/ef-mvc/…? And can you upload the whole project in one drive?Marina Liu
@Marina-MSFT I have tried to add the suggested changes, but now I just get two files shown as in the "Faulty reference" image. I am still unable to use "dotnet-ef" from powershell and am getting the "No executeable found matching command "dotnet-ef"KESU
Is that convenient for you to upload your project? Or you can upload a demo which has the same error messages.Marina Liu

2 Answers

1
votes

Disclaimer: I haven't tested any of the following suggestions.

Others are using this workaround: EF Core (1.0.0) Migrations On Azure App Services.

Another workaround with ASP.NET Core could be to add a command line argument (Program.cs) to allow executing .Database.Migrate() from the command line. And then you can add the VSTS deployment task that executes a powershell command/script on azure using this command line argument.

Yet another approach might be to have your CI drop the project file (*.csproj) with the EF Core tools reference in it in an artifact and then do a dotnet restore in the CD. The project file seems to be necessary because it's the only way I can see that you can instruct the dotnet tool on what to restore.

1
votes

I realize this is an old question, but for anyone else searching for the best way to handle EF migrations in Azure DevOps (aka VSTS), here's what I found.

EF migrations build the source, which can be problematic because you need the source and the release pipeline doesn't have all the same functionality for building that the build pipelines do.

My approach was:

  1. Generate a migration script in the build with the dotnet ef command.
  2. Publish the script as an artifact of the build.
  3. Run the script during deployment in the release pipeline.

See a full blog post with more details here.