发布ASP.NET Core应用程序时自动执行迁移
问题
使用Web Deploy将ASP 5应用程序发布到IIS时,是否有任何方法可以自动执行迁移代码(EF 7)?
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?
我尝试过
-
在
project.json
中,我在scripts
中添加了此代码:
in the
project.json
, I added this code in thescripts
:
"scripts" : {
"prepublish": ["dnx ef database update", "other commands..."],
"postpublish": ["dnx ef database update"]
}
"scripts" : {
"prepublish": ["dnx ef database update", "other commands..."],
"postpublish": ["dnx ef database update"]
}
没有人为我工作.
其他信息
我已按照链接上的说明进行操作使用Web部署将ASP 5 RC-1 Web应用程序部署到IIS.
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:
在ASP 4应用程序中使用Web部署我还有其他数据库选项:
Using web deploy in ASP 4 applications I have additional database options:
所以我在ef database
命令中添加了选项-environment
.现在可以使用了:
So I added the option -environment
to my ef database
command. Now it works:
"postpublish": ["dnx ef database update -e Staging"]
我有四个不同的appsettings.json
,每个环境都有不同的连接字符串.只需指出命令可以使用的环境即可.
I have four different appsettings.json
which different connection string for each environment. Just needed to indicate the environment for the command to work.