ConfigTransformer 1.1.2

dotnet add package ConfigTransformer --version 1.1.2
                    
NuGet\Install-Package ConfigTransformer -Version 1.1.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ConfigTransformer" Version="1.1.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ConfigTransformer" Version="1.1.2" />
                    
Directory.Packages.props
<PackageReference Include="ConfigTransformer" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ConfigTransformer --version 1.1.2
                    
#r "nuget: ConfigTransformer, 1.1.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ConfigTransformer@1.1.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ConfigTransformer&version=1.1.2
                    
Install as a Cake Addin
#tool nuget:?package=ConfigTransformer&version=1.1.2
                    
Install as a Cake Tool

ConfigTransformer

ConfigTransformer is a .NET extension that enhances your configuration pipeline by transforming placeholders in your configuration values using the IConfigurationBuilder. It replaces tokens like {Settings:Api:BaseUrl} with their actual values from the configuration at runtime.

Ideal for simplifying complex, cross-referenced config structures in .NET apps (e.g., appsettings.json, environment variables, etc.).

✨ Features

  • 🔁 Recursively replaces tokens like {Section:Sub:Key}
  • 🔍 Deep traversal of the configuration structure
  • ✅ Safe fallback for missing keys
  • 🔄 Prevents infinite substitution loops
  • 🛠️ Works directly on IConfigurationBuilder

📦 Usage

🔧 appsettings.json:

{
  "Settings": {
    "Api": {
      "BaseUrl": "https://api.example.com"
    }
  },
  "MyService": {
    "Endpoint": "{Settings:Api:BaseUrl}/v1/data"
  }
}

🌐 .NET App Initialization:

 builder.Configuration
     .SetBasePath(Directory.GetCurrentDirectory())
     .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
     .AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", optional: true)
     .AddEnvironmentVariables()
     .Transform(); // Replace all placeholders after config is loaded

✅ Output after Transform

"MyService": {
  "Endpoint": "https://api.example.com/v1/data"
}

🔄 How Placeholder Replacement Works

  • Transform() scans all key-value pairs in the config.
  • If a value contains {Some:Key}, it attempts to resolve Some:Key from the current configuration.
  • It supports nested or chained placeholders.
  • Up to 10 recursive passes are performed to ensure all placeholders are resolved.
  • If a placeholder cannot be resolved, it is left untouched.

📌 Best Practices

  • Call Transform() after your IConfigurationBuilder has loaded all sources.
  • Do not use circular placeholders – transformation is capped at 10 recursive passes.
  • Escape { and } with {{ or }} if you want them to remain literal.

📦 Installation

Install via NuGet

dotnet add package ConfigTransformer

Or via the NuGet Package Manager Console

Install-Package ConfigTransformer

📄 License

This project is licensed under the MIT License

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.