Vik*_*ngh 8 entity-framework-core entity-framework-migrations
在 launchSettings.json 中,定义了一些变量并使用这些变量进行应用程序。当我正常运行应用程序时,launchSettings.json 中可用的环境变量成功加载,并且应用程序完美运行。但是当我尝试添加迁移时,ef 工具会忽略 launchSettings.json 文件。
launchSettings.json 看起来像
{“MIN_LOG_LEVEL”:“警告”}
将 launchSettings.json 变量读取为的代码
config.AddEnvironmentVariables();
string logLevel = config["MIN_LOG_LEVEL"] // returing null
Run Code Online (Sandbox Code Playgroud)
一些代码快照
更新:我尝试使用 IIS 和 Kestrel Server,但在这两种情况下都会出现此问题。
在对这个问题进行了大量搜索之后,我发现了一件对我真正有帮助的事情。
当前可用的EF Core 工具不支持自动启动 launchSettings.json,如果我们想要获取 launchSettings.json 中存在的变量,那么我们需要手动解析该文件。
CLI添加了对 launchSettings.json 的支持,但到目前为止它仅适用于dotnet run命令。EF Core 工具无法自动获取 launchSettings.json 变量。
我从github问题中得知此功能将很快添加
如果您想利用 launchSettings.json,则可以按如下方式进行。
IConfigurationRoot configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), "Properties", "launchSettings.json"), optional: false, reloadOnChange: true)
.Build();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1349 次 |
| 最近记录: |