Entity framework core EF Core工具忽略.net Core 2.1和3.1中的launchSettings.json

Entity framework core EF Core工具忽略.net Core 2.1和3.1中的launchSettings.json,entity-framework-core,entity-framework-migrations,Entity Framework Core,Entity Framework Migrations,在launchSettings.json中,定义了一些变量,并使用这些变量创建应用程序。当我正常运行应用程序时,launchSettings.json中的可用环境变量成功加载,应用程序运行正常。但是,当我尝试添加迁移时,ef-tool会忽略launchSettings.json文件 launchSettings.json看起来像 { “最小日志级别”:“警告” } 将launchSettings.json变量读取为 config.AddEnvironmentVariables(); string

在launchSettings.json中,定义了一些变量,并使用这些变量创建应用程序。当我正常运行应用程序时,launchSettings.json中的可用环境变量成功加载,应用程序运行正常。但是,当我尝试添加迁移时,ef-tool会忽略launchSettings.json文件

launchSettings.json看起来像

{ “最小日志级别”:“警告” }

将launchSettings.json变量读取为

config.AddEnvironmentVariables();
string logLevel = config["MIN_LOG_LEVEL"] // returing null
代码的一些快照

Program.cs

launchSettings.json


更新:我尝试了IIS和Kestrel服务器,但在这两种情况下都出现了此问题。

在搜索了大量有关此问题的信息后,我发现了一件真正对我有帮助的事情

当前可用的EF核心工具不自动支持launchSettings.json,如果我们想获得launchSettings.json中存在的变量,那么我们需要手动解析该文件

CLI增加了对launchSettings.json的支持,但到目前为止,它仅适用于dotnet run命令EF Core tools没有自动获取launchSettings.json变量的功能

这项功能将在我从

如果您想利用launchSettings.json,那么您可以按如下方式操作

IConfigurationRoot configuration = new ConfigurationBuilder()
            .SetBasePath(Directory.GetCurrentDirectory())
            .AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), "Properties", "launchSettings.json"), optional: false, reloadOnChange: true)
            .Build();

您是在使用IIS还是Kestrel?@mvermef我在运行应用程序和迁移时都在使用IIS。