![]() |
VOOZH | about |
dotnet add package DotNetCore.Azure.Configuration.KvSecrets --version 10.0.100
NuGet\Install-Package DotNetCore.Azure.Configuration.KvSecrets -Version 10.0.100
<PackageReference Include="DotNetCore.Azure.Configuration.KvSecrets" Version="10.0.100" />
<PackageVersion Include="DotNetCore.Azure.Configuration.KvSecrets" Version="10.0.100" />Directory.Packages.props
<PackageReference Include="DotNetCore.Azure.Configuration.KvSecrets" />Project file
paket add DotNetCore.Azure.Configuration.KvSecrets --version 10.0.100
#r "nuget: DotNetCore.Azure.Configuration.KvSecrets, 10.0.100"
#:package DotNetCore.Azure.Configuration.KvSecrets@10.0.100
#addin nuget:?package=DotNetCore.Azure.Configuration.KvSecrets&version=10.0.100Install as a Cake Addin
#tool nuget:?package=DotNetCore.Azure.Configuration.KvSecrets&version=10.0.100Install as a Cake Tool
The DotNetCore.Azure.Configuration.KvSecrets based on Azure.Extensions.AspNetCore.Configuration.Secrets.
Install the package with DotNetCore.Azure.Configuration.KvSecrets:
Version 10.x.x : supports only .NET 10.0
dotnet add package DotNetCore.Azure.Configuration.KvSecrets
You need an Azure subscription and [Azure Key Vault][keyvault_doc] to use this package.
To create a new Key Vault, you can use the Azure Portal, Azure PowerShell, or the Azure CLI. Here's an example using the Azure CLI:
az keyvault create --name MyVault --resource-group MyResourceGroup --location westus
az keyvault secret set --vault-name MyVault --name MySecret --value "hVFkk965BuUv"
Can be used in conjunction with DotNetCore Azure Configuration KeyVault Certificates.
Add configuration provider with WebHostBuiler initialization.
Program.cs
var builder = WebApplication.CreateBuilder(args);
builder.AddKeyVaultConfigurationProvider();
StartupExt.cs
Used DotNetCore Configuration Templates to inject secrets into Microservice configuration. (Add to project nuget package DotNetCore.Configuration.Formatter.)
public static void AddKeyVaultConfigurationProvider(this WebApplicationBuilder builder)
{
var credential = new DefaultAzureCredential(
new DefaultAzureCredentialOptions()
{
ExcludeSharedTokenCacheCredential = true,
ExcludeVisualStudioCodeCredential = true,
ExcludeVisualStudioCredential = true,
ExcludeInteractiveBrowserCredential = true
});
var optionsKv = builder.Configuration
.GetTypeNameFormatted<AzureKvConfigurationOptions>();
// Adds Azure Key Valt configuration provider.
builder.Configuration.AddAzureKeyVault(credential, optionsKv);
}
appsettings.json
"AzureKvConfigurationOptions": {
"ConfigurationSectionPrefix": "secret",
"VaultUri": "https://secrets128654s235.vault.azure.net/",
"VaultSecrets": [
"service-bus-Developement-connection",
"sql-Developement-password",
"sql-Developement-user"
"service-bus-Production-connection",
"sql-Production-password",
"sql-Production-user" ]
}
The Azure Identity library provides easy Azure Active Directory support for authentication.
Read more about configuration in ASP.NET Core.
Use DotNetCore Configuration Templates to inject secrets into Microservice configuration.
Add to project nuget package DotNetCore.Configuration.Formatter.
DOTNET_RUNNING_IN_CONTAINER=true
ASPNETCORE_ENVIRONMENT=Development
...
host_environmet=datacenter
public class ApplicationConfiguration
{
public bool IsDocker {get; set;}
public string RunLocation {get; set;}
public string AppEnvironment {get; set;}
public string BusConnection {get; set;}
public string DbUser {get; set;}
public string DbPassword {get; set;}
}
{
"AzureKvConfigurationOptions": {
"ConfigurationSectionPrefix": "secret",
"VaultUri": "https://secrets128654s235.vault.azure.net/",
"VaultSecrets": [
"service-bus-Development-connection",
"sql-Development-password",
"sql-Development-user",
"service-bus-Production-connection",
"sql-Production-password",
"sql-Production-user" ]
}
ApplicationConfiguration:{
"IsDocker": "{DOTNET_RUNNING_IN_CONTAINER??false}",
"RunLocation":"{host_environmet??local}",
"AppEnvironment":"{ENVIRONMENT}",
"BusConnection":"{secret:service-bus-{ENVIRONMENT}-connection}",
"DbPassword":"{secret:sql-{ENVIRONMENT}-password}",
"DbUser":"{secret:sql-{ENVIRONMENT}-user}"
}
}
var applicationConfig = Configuration.UseFormater()
.GetSection(nameof(ApplicationConfiguration))
.Get<ApplicationConfiguration>();
or with shorthand
var applicationConfig = Configuration.GetTypeNameFormatted<ApplicationConfiguration>();
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
Only supports the .net 8.0.