ef核心在更新数据库期间不使用ASPNETCORE_ENVIRONMENT [英] ef core don´t use ASPNETCORE_ENVIRONMENT during update-database

查看:158
本文介绍了ef核心在更新数据库期间不使用ASPNETCORE_ENVIRONMENT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Visual Studio通过一定的迁移来更新所有环境。

I use visual studio to update all my environments with a certain migration. It had worked fine using the command below.

update-database -Migration initMigrationProduct -c ProductContext -Environment Production

在ef core 2.0中,此命令已更改,参数-Environment已删除。

In ef core 2.0 this command have been changed and parameter -Environment have been removed. in docs it said.


在2.0版本中,您可以使用ASPNETCORE_ENVIRONMENT环境变量

"With 2.0, you can use the ASPNETCORE_ENVIRONMENT environment variable instead."

https://docs.microsoft.com/zh-cn/ef/core/miscellaneous/cli/dotnet

我现在尝试了各种方法,但是当我使用ef core 2.0运行更新数据库时,它不使用 ASPNETCORE_ENVIRONMENT 变量。我试图在注册表中设置应用程序属性。

I have now tried on all kind of ways but when i run the update-database with ef core 2.0 it don´t use the ASPNETCORE_ENVIRONMENT variable. I tried to set in registry, application properties.

请让我知道我需要做些什么才能在更新不同的环境时使用它?

Please let me know what I need to do to get this working with updating diffrent environments?

如果我

推荐答案

在Visual Studio中使用包管理器是一种我的死胡同。
解决方案是:

Using the package manager in Visual Studio was a dead end for me. The solution was:


  1. 在.csproj中的以下启动项目中添加以下内容:

  1. Add below in .csproj in the starter project in solution:

<ItemGroup>
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
</ItemGroup>


  • 打开命令工具(cmd)并进入与.csproj相同的文件夹以进行启动项目位于(默认项目)。

  • Open the command tool(cmd) and go the the same folder as .csproj for start project are located(Default project).

    按照Anton Toshik的建议运行命令 set ASPNETCORE_ENVIRONMENT = Production

    Run the command as Anton Toshik suggested set ASPNETCORE_ENVIRONMENT=Production

    4,然后运行命令 dotnet ef database update initMigrationProduct -c ProductContext 现在可以正常工作。

    4.Then run the command dotnet ef database update initMigrationProduct -c ProductContext And now it works.

    备注:在此命令中数据库和早期版本以来,更新的位置已更改。而且没有用于迁移的参数/代码。在澄清之后,文档会进行更多说明:
    https:/ /docs.microsoft.com/en-us/ef/core/miscellaneous/cli/dotnet

    REMARK: in this command database and update have changed place since earlier versions. And there are no argument/code for migration. The docs explain more after this clarification:
    https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/dotnet

    这篇关于ef核心在更新数据库期间不使用ASPNETCORE_ENVIRONMENT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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