访问另一个项目 app.config 属性? [英] Accessing another projects app.config properties?

查看:33
本文介绍了访问另一个项目 app.config 属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的解决方案中有两个项目,在本示例中,我将它们称为项目 A 和 B.

I have two projects within my solution, for this example I will call them project A and B.

项目 B 引用 A.项目 B 可以访问项目 A 的 app.config 属性吗?

Project B references A. Can Project B access the app.config properties of project A?

我希望访问 A 的 app.config 中的应用密钥字符串.

I wish to access an app key string within the app.config of A.

string tfsUri = ConfigurationManager.AppSettings["TfsUri"];

推荐答案

这通常不是一个好主意,因为您在项目之间引入了硬依赖关系.因此,如果您可以复制粘贴配置值,这将使您的项目自包含(但是,这会引入配置值的重复).

That's generally not a good idea, as you introduce hard dependencies between the projects. So if you can copy-paste config value, that will make your projects self-contained (however, this introduces duplication of config value).

您也可以自动执行此操作,以便在构建项目时自动解析配置依赖项.

You can also automate this, so that when you build a project the configuration dependency is automatically resolved.

话虽如此,还有其他选项,在每种情况下,您可能更喜欢使用其他选项.您的其他选择是:

Having-said this, there are other options, and in each case you may prefer to use something else. Your other options are:

这篇关于访问另一个项目 app.config 属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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