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

查看:27
本文介绍了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:在这个命令中,databaseupdate 与早期版本相比发生了变化.并且没有用于迁移的参数/代码.文档在此澄清后进行了更多解释:
    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天全站免登陆