Used the local SQL connection string for development, starting testing and added KeyVault storage for the connection string in Azure...So in the project appsettings.json contains the connection string to Azure:
{"ConnectionStrings": {"DefaultConnectionLocal": "@AzureKeyVault(ConnectionStrings--DefaultConnection)"},"Logging": {"LogLevel": {"Default": "Information","Microsoft.AspNetCore": "Warning" } },"AllowedHosts": "*"}
and with appsettings.Development.json:
{"ConnectionStrings": {"DefaultConnection": "Data Source=MY_LOCAL_SERVER\\SQLEXPRESS;..."},"DetailedErrors": true,"Logging": {"LogLevel": {"Default": "Information","Microsoft.AspNetCore": "Warning","Microsoft.Hosting.Lifetime": "Information","Microsoft.AspNetCore.SignalR": "Debug" } }}Program.cs
var builder = WebApplication.CreateBuilder(args);var keyVaultEndpoint = new Uri(Environment.GetEnvironmentVariable("VaultUri"));builder.Configuration.AddAzureKeyVault(keyVaultEndpoint, new DefaultAzureCredential());// Add services to the container.builder.Services.AddRazorComponents() .AddInteractiveServerComponents() .AddInteractiveWebAssemblyComponents();builder.Services.AddCascadingAuthenticationState();builder.Services.AddScoped<IdentityUserAccessor>();builder.Services.AddScoped<IdentityRedirectManager>();builder.Services.AddScoped<AuthenticationStateProvider, PersistingRevalidatingAuthenticationStateProvider>();builder.Services.AddAuthentication(options => { options.DefaultScheme = IdentityConstants.ApplicationScheme; options.DefaultSignInScheme = IdentityConstants.ExternalScheme; }) .AddIdentityCookies();var conn = builder.Configuration.GetConnectionString("DefaultConnection");...Without this line on Progam.cs
builder .Configuration .AddAzureKeyVault(keyVaultEndpoint, new DefaultAzureCredential());Load local connection string again...
What would be the correct way to use environment variables with Azure Key Vault in Blazor hybrid applications? (Without having to comment any line of code for test environments)