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

查看:41
本文介绍了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 has been changed and parameter -Environment has been removed. In the docs it said.

"在2.0中,您可以使用ASPNETCORE_ENVIRONMENT环境变量代替."

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

https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/dotnet

我现在已经尝试了各种方法,但是当我使用ef core 2.0运行 update-database 时,它没有使用 ASPNETCORE_ENVIRONMENT 变量.我试图在注册表中设置应用程序属性.

I have now tried all kinds of ways but when I run the update-database with ef core 2.0 it doesn'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 to update different environments?

如果我使用不同的 launchsettings 启动应用程序,则可以正常运行,但不能使用程序包管理器控制台.

If I start the application with different launchsettings it works but not using the package manager console.

推荐答案

在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.

    REMARK :此命令中的 database update 自早期版本以来已更改.而且没有用于迁移的参数/代码.在澄清后,文档将进行更多说明:
    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天全站免登陆