Amir Katz
Amir Katz

Reputation: 1037

Manage configuration per environment

How can I instruct app.config to use different reference per environment?

For example: I have a configuration folder that contains 3 folders - Dev, QA and Prod

- Configuration
    - Dev
        * AppSettings.config
    - QA
        * AppSettings.config
    - Prod
        * AppSettings.config

My app.config have this reference

<appSettings configSource="Configuration\Dev\AppSettings.config" />

I would like to have something like

<appSettings configSource="Configuration\[$ENV]\AppSettings.config" />

$ENV config should be defined in appSettings or if not possible other external source.

Also what is the best practice to manage that? (without using fancy Chef server or configuration server).

**I'm also trying to avoid post script manipulation.**

Upvotes: 5

Views: 8653

Answers (2)

Amir Katz
Amir Katz

Reputation: 1037

Another solution can be using environment variables: Using environment variables for .config file in .NET

Then bootstrap the application to change the app.config at runtime http://www.codeproject.com/Articles/12589/Modifying-Configuration-Settings-at-Runtime

Upvotes: 1

Mat&#237;as Fidemraizer
Mat&#237;as Fidemraizer

Reputation: 64943

You need to use XML configuration file trasforms (see this MSDN article).

Since default configuration transforms are implemented for Web.config, you need to use a Visual Studio extension to get this feature to any configuration file. Slow Cheetah is a good one.

Upvotes: 3

Related Questions