FSharp.Appsettings
1.0.0
See the version list below for details.
dotnet add package FSharp.Appsettings --version 1.0.0
NuGet\Install-Package FSharp.Appsettings -Version 1.0.0
<PackageReference Include="FSharp.Appsettings" Version="1.0.0" />
paket add FSharp.Appsettings --version 1.0.0
#r "nuget: FSharp.Appsettings, 1.0.0"
// Install FSharp.Appsettings as a Cake Addin
#addin nuget:?package=FSharp.Appsettings&version=1.0.0
// Install FSharp.Appsettings as a Cake Tool
#tool nuget:?package=FSharp.Appsettings&version=1.0.0
FSharp.Appsettings - FSharp
Minimalistic environment-sensitive appsettings.json
importer.
Usage
Define FSHARP_ENVIRONMENT
as an environment variable. For development this will normally be done by creating a
launchSettings.json file:
{
"profiles": {
"Development": {
"commandName": "Project",
"environmentVariables": {
"FSHARP_ENVIRONMENT": "Development"
}
}
}
}
You can then run this code to load one or two appsettings.json
files with this code:
open FSharp.Appsettings
let appsettings = Appsettings.Load ()
// Or by using a type
let typedAppsettings = Appsettings.LoadTyped<Model> ()
appsettings.json
will always be loaded, while appsettings.{FSHARP_ENVIRONMENT}.json
will be loaded if
FSHARP_ENVIRONMENT is defined as an environment variable.
Properties from appsettings.json
will be overwritten by the environment specific
appsettings.
Arrays will be added together if a value does not already exist in the array.
Example
// appsettings.json
{
"Env": "Root",
"CORS": {
"AllowedOrigins": [
"https://localhost:3000", "https://fsharp.org"
]
},
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information",
"Test": "Critical"
}
},
"OnlyRoot": "Root"
}
// appsettings.Development.json (FSHARP_ENVIRONMENT=Development)
{
"Env": "Development",
"CORS": {
"AllowedOrigins": [
"https://localhost:3000"
]
},
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
},
"OnlyDev": "Dev"
}
// Resulting object after Appsettings.load ()
{
"Env": "Development",
"CORS": {
"AllowedOrigins": [
"https://localhost:3000", "https://fsharp.org"
]
},
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information",
"Test": "Critical"
}
},
"OnlyDev": "Dev",
"OnlyRoot": "Root"
}
Note: This NuGet does not support defining secrets by defining <UserSecretsId>
in the .csproj
file.
This is a bit of an opinionated design choice since I personally prefer just defining "local only" variables in
appsettings.Development.json that you simply do not commit (in this project it is committed as an example 😃 ).
Committing
Important to run this before committing (assuming you have GPG key set up)
git config commit.gpgsign true
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. 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. |
-
net6.0
- FSharp.Core (>= 6.0.6)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.