views:

246

answers:

2

Hello,

We're a small team, working on a asp.net web project, as well as service, both projects dependent on a shared class library.

We'd like to have the class library settings different per developer (and later on for production). In settings are included sensitive information, such as passwords, as well as hostnames.

How should we assign these settings ?

Unless I'm wrong, web.config/application settings aren't good enough, as they don't work for the shared class library.

ps: Also, some variables should be statically linked, and the rest (such as connectionstrings) should be dynamic.

+1  A: 

The web.config app.config files are read from whatever website/app your are running. I.E., Any app settings files in the class library are not used. e.g. any references to ConfigurationManager.ConnectionStrings ConfigurationManager.AppSettings within your class library will use whichever web.config/app.config that is defined in the app that is using the class library and not any .config you may have setup within the class library itself.

The easiest way to manage different settings per developer and for production is to have your config stored in a different file e.g.

<appSettings configSource="Web.appSettings.dev.config"/>

Each dev has their own Web.appSettings.dev.config which is not in source control. When in production you just change to:

<appSettings configSource="Web.appSettings.live.config"/>

You just need to make sure you have some kind of template Web.appSettings.template.config in svn that is the master but does not have any settings in it and manually manage making sure any new keys or connection strings that are added to the template also get added to each devs file and the production file.

Ben Robinson
Would the "Web.appSettings.dev.config" file be read always with this filename ? as I've tried adding a Settings resources file before, and it seems class libraries do NOT read them.
What do you mean by a "a Settings resources file" i am talking about the web.config and the app.config file and how to move different section such as the appSettings section or the connectionstrings section into seperate files. Class libraries read their settings from whatever app is using them.
Ben Robinson
Yes, when I ran my appname.exe, it read only appname.exe.config, and no other file.I do not want to have multiple setting files: appname1.exe.config, appname2.exe.config, web.config.
It will only read appname.exe.config, what I am describing is that instead of keeping your connection string and app settings in the appname.exe.config keep them in other files different for each developer and for production, then in your app.config your appSetting section just points to this other file using the configSource attribute as per my example. THen you have 1 app.settings file that is the same for everyone but each developer has their own version of the file pointd to by the config source attribute. You can allso do this for your connectionstrings section.
Ben Robinson
It has just occured to me what your problem might have been in the past. In VS on the properties of the Web.appSettings.dev.config file you need to make sure that "copy to output folder" is set to "copy always" or "copy if newer", if the file does not get copied then it will silently fail to read it.
Ben Robinson
A: 

You can also use NANT to have per developer configuration files.

More informations on my blog.

Best regards,

Florian DREVET