ServiceBusTrigger 选择了错误的配置文件

问题描述 投票:0回答:1

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

我有以下代码来根据

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 访问密钥,如

_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
属性正在寻找
ServiceBus
内的键
local.settings.json
而不是
local.dev.settings.json
,因为我在 VS 中将
ASPNETCORE_ENVIRONMENT
设置为
dev
。我该如何解决这个问题?

警告:在 local.settings.json 中找不到名为“ServiceBus”的值 与“serviceBusTrigger”上设置的“connection”属性匹配

c# azure azure-functions azureservicebus
1个回答
0
投票

这个时候你不能。带有连接字符串的触发器(例如 Azure 服务总线)需要在开发期间在

local.settings.json
中找到连接字符串,并在部署时通过设置将其设置为环境变量。

此线程适用于新的 SDK,但仍然与您的问题相关,并包含详细信息。

© www.soinside.com 2019 - 2024. All rights reserved.