ef core 在更新数据库期间不使用 ASPNETCORE_ENVIRONMENT

ef core doesn#39;t use ASPNETCORE_ENVIRONMENT during update-database(ef core 在更新数据库期间不使用 ASPNETCORE_ENVIRONMENT)
本文介绍了ef core 在更新数据库期间不使用 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 core 在更新数据库期间不使用 ASPNETCORE_ENVIRONMENT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

  • 本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

    相关文档推荐

    DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
    Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
    Programmatically show the desktop(以编程方式显示桌面)
    c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
    InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
    LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)