1

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?

Sayed Ibrahim Hashimi
  • 43,864
  • 17
  • 144
  • 178
Boris Callens
  • 90,659
  • 85
  • 207
  • 305
  • 1
    why not use config transforms: http://stackoverflow.com/questions/3004210/app-config-transformation-for-projects-which-are-not-web-projects-in-visual-stud – linkerro Mar 09 '12 at 16:02

3 Answers3

2

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

KMoraz
  • 14,004
  • 3
  • 49
  • 82
1

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.

Justin Pihony
  • 66,056
  • 18
  • 147
  • 180
-1

Consider using ant/maven or something like this

Plamen Paskov
  • 144
  • 3
  • 10