Locate and load environment variables defined when provisioning an Azure Developer CLI project.
If you do not already have an Azure Developer CLI (azd) project, you can create one:
azd init
Add a package reference to dotazure
to your project:
dotnet add package DotAzure
After you define some resources e.g., an Azure Key Vault,
you can provision those resources which will create a .env
file with any output
parameters:
azd up
After azd up
provisions resources and creates a .env
file, you can call Loader.Load()
to load those environment variables
from the default environment e.g.,
using DotAzure;
Loader.Load();
// Assumes bicep contains e.g.
//
// output AZURE_KEYVAULT_URL string = kv.properties.vaultUri
Console.WriteLine($"AZURE_KEYVAULT_URL={Environment.GetEnvironmentVariable("AZURE_KEYVAULT_URL")}");
If you want to customize behavior, you can call Loader.Load()
with LoadOptions
to set a builder-like AzdContext
object.
Licensed under the MIT license.