Ef core migrations in full .net project in VSTS

廉价感情. 提交于 2019-12-24 12:07:56

问题


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


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/44755768/ef-core-migrations-in-full-net-project-in-vsts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!