Easy to use tool to config transformations for JSON, XML and YAML.
C# PowerShell
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.vscode VS Code settings added Jun 13, 2016
assets Initial readme added Jun 13, 2016
build Build fix Dec 19, 2017
logo Logo added to nuget package Jun 18, 2016
nuspecs Nuspec version updated Dec 17, 2017
samples Samples updated Jun 21, 2016
src ILRepack moved from project file into build template Dec 19, 2017
.gitignore Build scripts added Jun 13, 2016
LICENSE Initial commit Jun 8, 2016
readme.md Version updated Dec 16, 2017

readme.md

AppVeyor Github Releases NuGet Visual Studio Marketplace

Magic Chunks

Easy to use tool to config transformations for JSON, XML and YAML.


Everyone remember XML Document Transform syntax to transform configuration files during the build process. But world is changing and now you can have different config types in your .NET projects.

Magic Chunks allows you to transform you JSON, XML and YAML files. You can run it at MSBuild, Cake, PSake or Powershell script as well as use Visual Studio Team Services build extension. Also, it's possible to reference Magic Chunks from your .NET projects in more complicated cases.

How it works

The main idea is quite simple. Magic Chunks represents transformation as a key-value collection.

The key contains path in the source file which should be modified, and the value contains data for this path in modified file.

If you are using Magic Chunks from .NET or Cake, you can also pass in any keys to be removed into the constructor.

XML

Imagine you have following XML based configuration file.

<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.5.1" />
    <authentication mode="None" />
  </system.web>
</configuration>

So following transformations could be applied to this config:

{
  "configuration/system.web/compilation/@debug": "false",
  "configuration/system.web/authentication/@mode": "Forms"
}

As a result you will have config like this:

<configuration>
  <system.web>
    <compilation debug="false" targetFramework="4.5.1" />
    <authentication mode="Forms" />
  </system.web>
</configuration>

JSON

The same approach works if you have JSON based configuration:

{
  "ConnectionStrings": {
    "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=webapp"
  }
}

Transformation for the config could be:

{
  "ConnectionStrings/DefaultConnection": "Data Source=10.0.0.5;Initial Catalog=Db1;Persist Security Info=True"
}

After transformation you will have:

{
  "ConnectionStrings": {
    "DefaultConnection": "Data Source=10.0.0.5;Initial Catalog=Db1;Persist Security Info=True"
  }
}

Supported formats

Magic Chunks supports following file formats:

  1. XML
  2. JSON
  3. YAML

Getting started

Let's say you have appsettings.json file at C:\sources\project1 folder:

{
  "ConnectionStrings": {
    "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=webapp"
  }
}

To use Magic Chunks download latest release manually or get it directly from Nuget.

For example we will use Powershell to transform configuration file. To do this you have to write something like this:

Import-Module .\MagicChunks.psm1

Format-MagicChunks -path C:\sources\project1\appsettings.json -transformations @{
 "ConnectionStrings/DefaultConnection" = "Data Source=10.0.0.5;Initial Catalog=Db1;Persist Security Info=True"
}

To transform config files you can use any approach you like:

To learn more check wiki page.

Contributions

Any contributions are welcome. Most probably someone will want to extend it with additional formats. So feel free to make pull requests for your changes. Read contribution guidelines to start.

License

Magic Chunks is released under the MIT License.