Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different configuration settings per developer for c# class library

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.

like image 684
user145100 Avatar asked Jun 04 '10 09:06

user145100


People also ask

What is configuration in web development?

A configuration file (web. config) is used to manage various settings that define a website. The settings are stored in XML files that are separate from your application code. In this way you can configure settings independently from your code. Generally a website contains a single Web.

Where should app config be located?

A typical location would be: C:\Windows\System32\inetsrv\ApplicationHost. config.


1 Answers

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.

like image 149
Ben Robinson Avatar answered Oct 19 '22 19:10

Ben Robinson