Question

Short
I want to set certain applicationSetting values to specific values only for my development machine in a config file that cannot be checked in. For this I was thinking to use the configSource attribute with a user.config file. This attribute, however throws an exception when the file is not present.

Extended
I have a library with the following app.config file:

<applicationSettings>
    <A.NameSpace.Settings>
        <setting name="ASettingName" serializeAs="String">
            <value>aSettingValue</value>
        </setting>
    </A.NameSpace.Settings>
</applicationSettings>

Another library is going to use this library and has two options and one described a bit further

  • Not fill in the A.NameSpace.Settings node so the default aSettingValue is used
  • Fill in the A.NameSpace.Settings node so the newly configured value is used

This is handy because our build script that prepares setups can now replace environment-dependant parameters (eg: servernames, ports etc)

Now a third option is to have a app.config like this:

<applicationSettings>
    <A.NameSpace.Settings configSource="user.config" />         
</applicationSettings>

and define the same value in a user.config file that is not checked in. This is awesome. Except that in not-dev environment this user.config file should not present and an exception will be thrown when the file is not found.

How can I define configuration values only for my dev machine?

Was it helpful?

Solution

I think SlowCheetah is what you are looking for.

Scott Hanselman blogged about it: SlowCheetah - Web.config Transformation Syntax now generalized for any XML configuration file

OTHER TIPS

You could use config transforms. I will find some documentation on how to accomplish this and post it shortly.

Here is the hanselman article real quick that may help.

Consider using ant/maven or something like this

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top