Wiki
Clone wikicontemplate / Home
An application configuration template system to easily manage multiple configuration files for multiple environments.
ConTemplate # - template based configuration file generation
An application configuration template system to easily manage multiple configuration files for multiple environments.
How it works
Configuration values are saved to a text file containing <name>:<value> entries. One .entries file is maintained per environment. (eg live.entries, dev.entries) (These files must be located in the same folder)
A template file is created alongside each configuration file. These are named in the format <ExistingConfigFilename.ext>.template
eg: App.Config.template will generate App.Config etc (Basically, the .template extension is dropped when the config file is generated so can be used for any file, config or other, where values need to be replaced)
Template files contain variable fields in the format {{<name>}} that will be replaced by the values in the entries file, where <name> is the key name in the entries files.
!! [url:See Documentation for usage|http://contemplate.codeplex.com/documentation]
Documentation
! ConTemplate - template based configuration file generation
An application configuration template system to easily manage multiple configuration files for multiple environments.
!! How it works
Configuration values are saved to a text file containing <name>:<value> entries. One .entries file is maintained per environment. (eg live.entries, dev.entries) (These files must be located in the same folder)
A template file is created alongside each configuration file. These are named in the format <ExistingConfigFilename.ext>.template
eg: App.Config.template will generate App.Config etc (Basically, the .template extension is dropped)
Template files contain variable fields in the format {{<name>}} that will be replaced by the values in the entries file.
! Usage
Running ConTemplate.exe with it's specific configuration parameters will generate the configuration files with the replaced values.
!! Configuration parameters (command line parameters):
Command line parameters are specified by a command then a space then the value. (if the value has spaces, wrap it "double quotes")
eg: ConTemplate.exe -entries "C:\Project Folder\Configuration"
|| Parameter || Required || Description || | -entries | Yes | Configuration entries folder, This is where all the .entries files are saved. | | -env | No | Environment Name (for example "dev" will load the "dev.entries" file. If the value is not set thsi will default to the current computer/machine name. | | -search | Yes | Top level folder to start searching for configuration templates, configuration files will be generated alongside the templates, this is recursive. | | -pathroot | No | The root folder to prepend, replacing "~\" on any entry values that start with "~\", value is set as-is if pathroot is not specified. This only works for file system paths, not URLs |
! Example Files:
!! Batch File: Config.bat
Create a batch file in the root of your solution that runs ConTemplate.exe, pointing to your configuration settings folder and the root folder of your project.
{code:powershell} %~dp0\Libs\ConTemplate\ConTemplate.exe -env dev -search %~dp0 -entries %~dp0Configuration -pathroot %~dp0DevelopmentFiles @pause
Notes: "%~dp0" in the batch file indicates the folder where batch file was launched. We are expecting a dev.entries file in the Configuration Folder We have set a pathroot to prepend a folder entry
!! Entries File
file naming convention: <enviroment>.entries
format: name:value
everything after the first ":" is included in the value
comment a line using #
dev.entries
{code:powershell}
Environment Dev Configuration entries
Note: comments can be placed in the .entries file, they need to start with a "#"
App Settings
Application.Name: My Demo Folder.Logs : c:\Logs\MyDemo\
Storage
Folder.FileStore: ~\UploadedFiles
!! Configuration Template:
App.config
{code:xml}
<configuration> <appSettings> <add key="Application.Name" Value="{{Application.Name}}" /> <add key="Folder.Logs" Value="{{Folder.Logs}}" /> <add key="Folder.FileStore" Value="{{Folder.FileStore}}" /> </appSettings> </configuration>>
See this in action! The download includes the above files, just extract and run the batch file
Enjoy!
Updated