我们可以在项目之间共享App.config的某些内容吗? [英] Can we share some contents of App.config between projects?

查看:76
本文介绍了我们可以在项目之间共享App.config的某些内容吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Visual Studio 2008解决方案中有两个独立的项目。两者都有自己的App.config。但是在一个项目中,我需要在另一个项目的App.config中定义一个或两个属性。可以共享其他项目中的App.config内容的一部分吗?

I have two independent projects in my Visual Studio 2008 solution. Both has its own App.config. But in one project, I need one or two properties defined in another project's App.config. Is it possible to share part of the App.config contents from other project?

推荐答案

是的-当然。任何配置节都可以外部化-例如:

Yes - of course. Any configuration section can be "externalized" - e.g.:

<appSettings configSource="AppSettings.DEV.config" />
<connectionStrings configSource="MyConnection.config" />

<system.net>
   <mailSettings>
      <smtp configSource="smtp.TEST.config" />

vs。

<system.net>
   <mailSettings>
      <smtp configSource="smtp.PROD.config" />

任何配置节都可以放在一个单独的文件中,该文件可以在项目之间共享-但没有任何配置节,不幸的是,有时有时要知道哪个是有点棘手。

Any configuration section can be put into a separate file that can be shared between projects - but no configuration section groups, and unfortunately, it's sometimes a bit tricky to know which is which.

此外,在某些情况下,Visual Studio会抱怨(使用红色波浪线强调) configSource应该是无效的,但实际上是在.NET config系统的 ConfigurationSection 对象上定义的。

Also, in some cases, Visual Studio will complain (using red wavy underlines) that the "configSource" supposedly isn't valid - but it is - it's defined on the ConfigurationSection object in the .NET config system.

更新:

开发人员似乎几乎不了解和使用的另一个功能是Visual Studio能够从其他位置添加现有文件的功能。项目作为链接


通过此操作,您可以将文件链接添加到本地项目中,它们将始终保持最新状态。 o日期。如果您需要执行某些文件级共享(例如,常用的配置文件等),则可以极大地提高生产力!

With this, you can add links to files into your local project, and they'll always be kept up to date. Great productivity booster if you need to do some file-level sharing (like for common configuration files or such)!

这篇关于我们可以在项目之间共享App.config的某些内容吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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