开发者

Different configuration settings per developer for c# class library

开发者 https://www.devze.com 2023-01-02 01:03 出处:网络
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'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 t开发者_StackOverflow社区he 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消