Configuration.EnvironmentVariablesFromFile
1.0.0
dotnet add package Configuration.EnvironmentVariablesFromFile --version 1.0.0
NuGet\Install-Package Configuration.EnvironmentVariablesFromFile -Version 1.0.0
<PackageReference Include="Configuration.EnvironmentVariablesFromFile" Version="1.0.0" />
paket add Configuration.EnvironmentVariablesFromFile --version 1.0.0
#r "nuget: Configuration.EnvironmentVariablesFromFile, 1.0.0"
// Install Configuration.EnvironmentVariablesFromFile as a Cake Addin #addin nuget:?package=Configuration.EnvironmentVariablesFromFile&version=1.0.0 // Install Configuration.EnvironmentVariablesFromFile as a Cake Tool #tool nuget:?package=Configuration.EnvironmentVariablesFromFile&version=1.0.0
AddEnvironmentVariablesFromFile
This package contains new configuration provider to get values from file.
This provider is similar to AddEnvironmentVariables
:
static void Main(string[] args)
{
var cfg = InitOptions<AppConfig>();
string server = cfg.Server;
string userId = cfg.UserName;
...
}
private static T InitOptions<T>() where T : new()
{
var config = InitConfig();
return config.Get<T>();
}
private static IConfigurationRoot InitConfig()
{
var env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
var builder = new ConfigurationBuilder()
.AddJsonFile($"appsettings.json", true, true)
.AddJsonFile($"appsettings.{env}.json", true, true)
.AddEnvironmentVariables();
return builder.Build();
}
In this case if exist token in json file that exist in AppConfig class like a property, is populated with this value.
Adding new provider:
var builder = new ConfigurationBuilder()
.AddJsonFile($"appsettings.json", true, true)
.AddJsonFile($"appsettings.{env}.json", true, true)
.AddEnvironmentVariables()
.AddEnvironmentVariablesFromFile();
Provider searches environment variables ending with suffix _FILE
(there is also a parameter in AddEnvironmentVariablesFromFile
method to change it) and the content will be used as the file name.
Then the contents of this file are read and entered as a value.
In previous example, AppConfig
class contains property Server
and if Environoment Variable contains:
- Server_FILE = /tmp/server.txt
Provider read the content of this file, and insert value into
Server
property.
This is useful in Docker containers or Kubernetes for passing parameters like secrets or config.
License
MIT ©
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Microsoft.Extensions.Configuration (>= 5.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 472 | 8/16/2021 |