gpt4 book ai didi

c# - 在独立的应用程序中运行迁移

转载 作者:行者123 更新时间:2023-11-30 23:18:35 24 4
gpt4 key购买 nike

我已经使用 dotnet 创建了一个独立的应用程序:

dotnet publish -c release

部署包本身包含 .net 核心运行时 - 因此如果有人想使用应用程序 - 不需要单独安装 .net 核心运行时。

但我的问题是...是否可以将 dotnet.exe 附加到部署包?

- 我的网络应用程序需要迁移的数据库:

dotnet ef database update

此命令无法从自包含应用程序运行(无法直接访问 dotnet.exe)。

这种情况下的场景是什么?我该如何处理?

最佳答案

解决方案是像这样将它添加到您的 Startup.cs 中

public void Configure(
IApplicationBuilder app,
// ... various other parameters that you may have and below add the context that you want to run Migrations
YourDbContext db1)
{
{
// run the migrations before other code
db1.Database.Migrate();
// ...
}

附言。这有点奇怪,但是您将它作为额外参数添加到 Configure 方法签名中并且它起作用了(我猜它会自动实例化 dbContext 对象并调用该方法)。它对我有用。

关于c# - 在独立的应用程序中运行迁移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40795364/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com