【发布时间】:2020-11-19 01:21:54
【问题描述】:
我正在转换我的 .net core 3.1 应用程序以在 VS Code 而不是 Visual Studio 19 中运行,它可以构建并运行,但我无法读取 appsettings.json 文件内容。它返回 null。
在 Startup.cs 中:
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
在我的课堂上:
var dbConnection = Configuration.GetSection("Database")["ConnectionString"];
这是我在 vs19 中调试时看到的,我清楚地看到从我的 appsettings.QA.json 文件返回的数据,但在 vs 代码中,它什么也没返回。
【问题讨论】:
标签: visual-studio-code configuration asp.net-core-3.1