VSTS中完整.net项目中的EF核心迁移 [英] Ef core migrations in full .net project in VSTS

本文介绍了VSTS中完整.net项目中的EF核心迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个针对整个.net框架的.net核心网络应用程序

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

我已经创建了一个类库(.net框架) 在这个dll中,我引用了ef内核并创建了一个上下文. 使用软件包管理器时,迁移工作正常.

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.

我当前面临的问题 我需要能够在VSTS部署期间使用迁移.

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

我尝试过 在VSTS中创建Powershell部署脚本以调用dotnet-ef命令.这不起作用,因为我无法在项目中安装Microsoft.EntityFrameworkCore.Tools.DotNet

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

我尝试在.csproj中手动添加引用 手动更新.csproj

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

推荐答案

免责声明:我尚未测试以下任何建议.

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

其他人正在使用此替代方法: EF Core( 1.0.0)在Azure App Services上迁移.

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

ASP.NET Core的另一种解决方法可能是添加命令行参数(Program.cs),以允许从命令行执行.Database.Migrate().然后,您可以使用此命令行参数添加VSTS部署任务,该任务在azure上以天蓝色执行powershell命令/脚本.

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.

另一种方法可能是让CI使用

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.

这篇关于VSTS中完整.net项目中的EF核心迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆