In the past developing a Timer Triggered Azure Function I’ve used GetConnectionStringOrSetting from Microsoft.Extensions.Configuration to load connection strings, secrets and regular settings. It didn’t matter where they lived, it would find them.
But in migrating to .NET 8 I’m not sure I should anymore? Looks like it depends on .NET standard and it no longer works with Microsoft.Extensions.Configuration.UserSecrets to load secrets from a secure folder when developing locally.
2
Answers
I just ended up stealing that one static function so I wouldn't have to re-write all the calls to it.
In .NET 8, avoid using
GetConnectionStringOrSetting
and instead use theIConfiguration
interface provided byMicrosoft.Extensions.Configuration
to access configuration settings to ensure compatibility with user secrets, environment variables, and configuration files.I tried with the below code by using
GetConnectionStringOrSetting
not worked as expected.To read from
appsettings.json
, environment variables, and user secrets. check below for sample configurationProgram.cs:
To access the configuration setting in function use
IConfiguration
.Function1.cs:
local.settings.json:
Output: