Different configuration settings per developer for c# class library

為{幸葍}努か 提交于 2019-12-06 02:17:10

问题


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:


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.



来源:https://stackoverflow.com/questions/2972903/different-configuration-settings-per-developer-for-c-sharp-class-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!