VS 2019 中 IIS Express 调试器的 .Net Core MVC appsettings.json 文件在哪里
Where is the .Net Core MVC appsettings.json file for the IIS Express debugger in VS 2019
我需要在 appsettings.json 文件中编辑连接字符串以调试 .Net Core MVC 应用程序。当我 运行 使用 IIS Express 调试器的应用程序时,我的应用程序构建为 bin\Debug\netcoreapp2.2
。在此目录中,我正在使用测试所需的值编辑我的 appsettings.Development.json 配置文件。我知道该应用程序正在提取 appsettings.json 文件的正确变体。但是,我不认为调试器正在查看 bin\Debug\netcoreapp2.2
中的文件,因为当我编辑该文件时,我的应用程序中不存在更改。 IIS Express 调试器从哪里加载 appsettings.json 文件?
更多上下文的屏幕截图。
我运行 来自这个工具栏的调试器。
调试器将文件生成为 bin\Debug\netcoreapp2.2
。
然后我编辑必要的 appsettings.json 文件。该文件不会在以后的构建中被覆盖,因为我将 "Copy To Output Directory" 属性 设置为 "Copy if Newer"
我验证了调试器的 ASPNETCORE_ENVIRONMENT 变量设置为 "Development"。
但是当我去调试我的应用程序时,我在项目的 appsettings.json 中获得了默认连接字符串,而不是在 bin\Debug\netcoreapp2.2
目录的 appsettings.json[= 中获得了修改后的连接字符串20=]
默认情况下,IConfiguration
读取项目文件夹下的*.json
文件。
要在 bin/Debug/netcoreapp2.2
等其他地方读取 *.json
文件,您可以像
这样配置 ConfigureAppConfiguration
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.ConfigureAppConfiguration((hostingContext, config) =>
{
config.AddJsonFile(
"bin/Debug/netcoreapp2.2/appsettings.Development.json", optional: false, reloadOnChange: true);
});
然后像
一样使用它
public class HomeController : Controller
{
private readonly IConfiguration configuration;
public HomeController(IConfiguration configuration)
{
this.configuration = configuration;
}
public IActionResult Index()
{
return Ok(configuration.GetConnectionString("DefaultConnection"));
//return View();
}
我需要在 appsettings.json 文件中编辑连接字符串以调试 .Net Core MVC 应用程序。当我 运行 使用 IIS Express 调试器的应用程序时,我的应用程序构建为 bin\Debug\netcoreapp2.2
。在此目录中,我正在使用测试所需的值编辑我的 appsettings.Development.json 配置文件。我知道该应用程序正在提取 appsettings.json 文件的正确变体。但是,我不认为调试器正在查看 bin\Debug\netcoreapp2.2
中的文件,因为当我编辑该文件时,我的应用程序中不存在更改。 IIS Express 调试器从哪里加载 appsettings.json 文件?
更多上下文的屏幕截图。
我运行 来自这个工具栏的调试器。
调试器将文件生成为 bin\Debug\netcoreapp2.2
。
然后我编辑必要的 appsettings.json 文件。该文件不会在以后的构建中被覆盖,因为我将 "Copy To Output Directory" 属性 设置为 "Copy if Newer"
我验证了调试器的 ASPNETCORE_ENVIRONMENT 变量设置为 "Development"。
但是当我去调试我的应用程序时,我在项目的 appsettings.json 中获得了默认连接字符串,而不是在 bin\Debug\netcoreapp2.2
目录的 appsettings.json[= 中获得了修改后的连接字符串20=]
默认情况下,IConfiguration
读取项目文件夹下的*.json
文件。
要在 bin/Debug/netcoreapp2.2
等其他地方读取 *.json
文件,您可以像
ConfigureAppConfiguration
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.ConfigureAppConfiguration((hostingContext, config) =>
{
config.AddJsonFile(
"bin/Debug/netcoreapp2.2/appsettings.Development.json", optional: false, reloadOnChange: true);
});
然后像
一样使用它public class HomeController : Controller
{
private readonly IConfiguration configuration;
public HomeController(IConfiguration configuration)
{
this.configuration = configuration;
}
public IActionResult Index()
{
return Ok(configuration.GetConnectionString("DefaultConnection"));
//return View();
}