每个开发不同的配置设置为C#类库 [英] Different configuration settings per developer for c# class library

查看:142
本文介绍了每个开发不同的配置设置为C#类库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们是一个小团队,在一个asp.net web项目的工作,以及服务,依赖于一个共享的类库这两个项目。

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 ?

除非我错了,web.config中/应用程序设置不够好,因为他们没有为共享类库工作。

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

PS:另外,一些变量应该静态链接,其余的(如的ConnectionStrings)应该是动态的。

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

推荐答案

的App.config文件的web.config文件是从任何网站读取/应用的运行。即,不使用类库中的任何应用程序的设置文件。例如您的类库内ConfigurationManager.ConnectionStrings ConfigurationManager.AppSettings任何引用都会使用在正在使用该类库,而不是你可能有类库本身设置任何的.config应用程序定义的web.config文件为准/ app.config中。

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"/>

每个开发都有自己的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"/>

您只需要确保你有某种模板Web.appSettings.template.config的SVN即是主但不具有任何设置,手动管理确保被添加到模板也被添加到每个开发者文件和生产文件中的任何新的键或连接字符串

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.

这篇关于每个开发不同的配置设置为C#类库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆