(using .NET 6.0)
I used these commands to set a connection string:
- dotnet user-secrets init
- dotnet user-secrets set ConnectionStrings:AppConfig "{myconnectionstring}"
but I can't figure out how to retrieve that connection string using IHostBuilder. This returns a null string:
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
private static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args).ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.ConfigureAppConfiguration((hostingContext, configurationBuilder) =>
{
configurationBuilder.AddAzureAppConfiguration(options =>
{
var azureAppConfigConnectionString = hostingContext.Configuration.GetConnectionString("AppConfig");

Even Iam getting the user secret value null with the code which you have provided.
I am able to retrieve the user secret with few changes.
Thanks @Christian Nagel for the code snippet.
configurationBuilder.Build();and then retrieve the value from the variable.My
Program.csfileOutput: