发布 ASP.NET Core 应用程序时自动执行迁移 [英] Automatically execute migrations when publishing ASP.NET Core app
问题描述
问题
在使用 Web Deploy 将 ASP 5 应用程序发布到 IIS 时,有什么方法可以自动执行迁移代码 (EF 7)?
我试过了
在
project.json
中,我在scripts
中添加了这段代码:<代码>脚本":{"prepublish": ["dnx ef 数据库更新", "其他命令..."],"postpublish": ["dnx ef 数据库更新"]}
没有一个对我有用.
附加信息
我按照此
在 ASP 4 应用程序中使用 web 部署我有额外的数据库选项:
所以我在我的 ef database
命令中添加了选项 -environment
.现在它可以工作了:
"postpublish": ["dnx ef database update -e Staging"]
我有四种不同的 appsettings.json
,它们为每个环境提供了不同的连接字符串.只需要指明命令运行的环境即可.
Question
Is there any ways that I can automatically execute the migration code (EF 7) when publishing my ASP 5 application to IIS using Web Deploy?
I Tried
in the
project.json
, I added this code in thescripts
:"scripts" : { "prepublish": ["dnx ef database update", "other commands..."], "postpublish": ["dnx ef database update"] }
none worked for me.
Additional Info
I followed the instructions on this link to deploy my ASP 5 RC-1 web application to IIS using web deploy.
After doing so in the publish settings I have:
Using web deploy in ASP 4 applications I have additional database options:
So I added the option -environment
to my ef database
command. Now it works:
"postpublish": ["dnx ef database update -e Staging"]
I have four different appsettings.json
which different connection string for each environment. Just needed to indicate the environment for the command to work.
这篇关于发布 ASP.NET Core 应用程序时自动执行迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!