dotnet watch run
webBuilder.ConfigureAppConfiguration((hostingContext, config) =>
{
config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
config.AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json", optional: true, reloadOnChange: true);
config.AddEnvironmentVariables();
})
.UseStartup()
.UseEnvironment(EnvironmentName.Development) // 添加这行
.UseWebRoot("wwwroot"); // 添加这行
在Visual Studio中,您还需要确保在属性视图中选择“开发”环境。
dotnet clean
dotnet build
请注意,以上方法适用于在开发期间运行应用程序时出现的问题。在将应用程序部署到生产环境时,不建议激活自动重新加载功能,以提高应用程序性能。