C#中,我们可以分享的App.config项目之间的一些内容是什么?我们可以、项目、内容、config

2023-09-02 11:58:08 作者:谁动了我的奶罩!

我在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配置系统。

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中,从不同的项目的添加现有文件为纽带的能力

UPDATE: another feature that hardly enough developers seem to know and use is the ability in Visual Studio to add existing files from a different project as a link:

通过这个,你可以添加链接到文件到您的本地项目,他们会始终保持最新。伟大的工作效率助推器,如果你需要做一些文件级共享(如常见的配置文件,或者这样的)!

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)!