gpt4 book ai didi

c# - ServiceBusTrigger 选择错误的配置文件

转载 作者:行者123 更新时间:2023-12-03 06:06:56 27 4
gpt4 key购买 nike

我的 Azure 函数项目中有 4 个配置文件,代表 4 个环境。

My configs

我有以下代码来根据 ASPNETCORE_ENVIRONMENT 红色特定于环境的文件

        var executionContextOptions = builder.Services.BuildServiceProvider()
.GetService<IOptions<ExecutionContextOptions>>().Value;

var currentDirectory = executionContextOptions.AppDirectory;

var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");

var config = new ConfigurationBuilder()
.SetBasePath(currentDirectory)
.AddJsonFile($"local.settings.{environment}.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
builder.Services.AddSingleton<IConfiguration>(config);

我可以通过 DI 访问 key ,例如 _configuration.GetSection("Values")我现在有一个 ServiceBusTrigger

[FunctionName("FuncEmployeeMessageActivity")]
public static void FuncEmployeeMessageActivity(
[ServiceBusTrigger("queue-xxxxx", Connection = "ServiceBus")] string message,
ILogger log)
{
try
{
// Process the message received from the Service Bus queue.
log.LogInformation($"Received message: {message}");
}
catch (Exception)
{
throw;
}
}

此处,Connection 属性正在寻找 local.settings.json 中的键 ServiceBus,而不是 local.dev.settings .json 因为我在 VS 中将 ASPNETCORE_ENVIRONMENT 设置为 dev 。我该如何解决这个问题?

Warning: Cannot find value named 'ServiceBus' in local.settings.jsonthat matches 'connection' property set on 'serviceBusTrigger'

最佳答案

目前你不能。具有连接字符串的触发器(例如 Azure 服务总线)需要在开发期间在 local.settings.json 中找到连接字符串,并在部署时通过设置将其设置为环境变量。

This thread适用于新的 SDK,但仍然与您的问题相关,并附有详细信息。

关于c# - ServiceBusTrigger 选择错误的配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77215511/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com