我正在尝试在使用 Azure WebJob SDK 的 AppService 中设置 Azure WebJob。我遇到的问题是将
AzureWebJobsStorage
设置在 appsettings.json
或 Settings.job
之外。应用程序无法启动,因为它找不到存储连接字符串,然后它无法为 WebJob 的函数编制索引并退出并出现未处理的异常。
如果我将值放入 JSON 文件并将其添加到
Program.cs
中,那么它会正常工作,但我想避免这样做,因为我已经将它放在密钥库中并通过管道传输到环境变量中。如何让 WebJob SDK 像识别 appsettings.json
或 Settings.job
属性一样识别环境变量?
我在
Program.cs
中尝试过的内容:
var builder = new HostBuilder();
...
builder.ConfigureAppConfiguration((context, configurationBuilder) =>
{
configurationBuilder.AddJsonFile("Settings.job");
configurationBuilder.AddEnvironmentVariables();
// attempt to add in the missing value for SDK to use, doesn't work though
Environment.SetEnvironmentVariable("AzureWebJobsStorage", context.Configuration.GetValue<string>("AzureWebJobsStorage"));
});
...