Azure / Azure-Functions

1.11k stars 195 forks source link

Using a settings file with a different name is not working. #2412

Open wmmihaa opened 11 months ago

wmmihaa commented 11 months ago

Function App name: microServiceBus.functions Tools used: VS2022 - Version 17.4.4 & Version 17.7.4 .Net runtime: 6 Runtime: dotnet-isolated Language: C# Core Tools Version: 4.0.5390 Commit hash: N/A (64-bit) Function Runtime Version: 4.25.3.21264

We have an function app used by many customers, hence we've had to updated the local.settings.json dependin on which the customer we've been working with. Upon migrating from v4 In-proc to v4 isolated we've instead created multiple settings files, one for each customer as this has worked fine for our web applications. However, using a settings file with a different name is not working.

var host = new HostBuilder()
    .ConfigureAppConfiguration((context, config) => {
        //config.AddJsonFile("local.settings.json", optional: true);
        config.AddJsonFile("local.settings.CUSTOMER.json", optional: true);

        config.AddEnvironmentVariables();
    })
ConfigureLogging(logging => ...)
.ConfigureFunctionsWorkerDefaults()
.ConfigureServices((context, services) => ...)
.Build();

host.Run();

Behavior: If the local.settings.json does not exist, the process will not start with the following error:

Azure Functions Core Tools
Core Tools Version:       4.0.5390 Commit hash: N/A  (64-bit)
Function Runtime Version: 4.25.3.21264

Can't determine project language from files. Please use one of [--csharp, --javascript, --typescript, --java, --python, --powershell, --custom]
Can't determine project language from files. Please use one of [--csharp, --javascript, --typescript, --java, --python, --powershell, --custom]
Can't determine project language from files. Please use one of [--csharp, --javascript, --typescript, --java, --python, --powershell, --custom]
[2023-10-06T10:30:41.620Z] Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.IncidentHandler_SendEmail'. Microsoft.Azure.WebJobs.Host:

Interestingly, it seams the configuration is evaluated before the ConfigureAppConfiguration method is executed, as if I set a breakpoint in the method I can se the output of funciton list before the breakpoint is hit.

bhagyshricompany commented 11 months ago

Thanks for reporting will check and update. Thanks

auzwu commented 3 weeks ago

Azure Functions using dotnet-isolated v4 model are hosted inside the Azure functions host (via func.exe tooling locally). I assume the host specifically looks for FUNCTIONS_WORKER_RUNTIME setting in local.settings.json to start the worker process.

While its possible to inject additional app settings in the function startup, those are not picked up by the "outer" function host itself. Some settings like the worker runtime, version and connection strings are required by the host to properly index and wire up the function triggers.

Looks like you have to stick to local.settings.json or env variables.