Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
255 views
in Technique[技术] by (71.8m points)

webdeploy - Automatically execute migrations when publishing ASP.NET Core app

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 the scripts:

    "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:

ASP 5 RC 1 publish to IIS using Web Deploy

Using web deploy in ASP 4 applications I have additional database options:

ASP 4 publish to IIS using Web Deploy

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Use context.Database.Migrate()

You can call this from your Startup class:

using (var context = new MyContext(...))
{
    context.Database.Migrate();
}

It will migrate your database to the latest version on application startup. But be careful doing it, maybe comment out this code and uncommend only when you want to run your migrations.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...