简体   繁体   English

App.config问题与同一解决方案中的许多项目有关

[英]App.config issue with many projects in same solution

I have a solution in visual studio 2010 which constists of 7 different projects. 我在visual studio 2010中有一个解决方案,它由7个不同的项目组成。 I want to keep some settings that is used by logic in project X in project X's app.config file. 我想保留项目X的app.config文件中项目X中的逻辑使用的一些设置。 However if I create an app.config like the one below: 但是,如果我创建一个app.config,如下所示:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
     <add key="PrimaryEmail" value="abc@foo.com"/>
     <add key="CCEmail1" value="def@foo.com"/>
  </appSettings>
</configuration>

and then in a class in project X uses code like this: 然后在项目X的类中使用如下代码:

ConfigurationManager.AppSettings["PrimaryEmail"]

it can't find it and ConfigurationManager.AppSettings.Count returns 0. 它找不到它,ConfigurationManager.AppSettings.Count返回0。

However if I create the same app.config in the StartUp project Y of the solution it finds the data in that one. 但是,如果我在解决方案的StartUp项目Y中创建相同的app.config,它会在该项中找到数据。

Is it possible somehow to use the information in app.config in project X in this case? 在这种情况下,是否有可能以某种方式使用项目X中的app.config中的信息? I guess it has to do soemthing with the fact that I have many projects in the same solution. 我想它必须做的事情是我在同一个解决方案中有很多项目。

config file in Project X is available in Project X only. Project X中的配置文件仅在Project X中可用。 If your startup project is Y, then you need to have config file in this project. 如果你的启动项目是Y,那么你需要在这个项目中有配置文件。 No other way to do this 别无他法

UPDATE: 更新:

As an option you can you post build event and run copy command to copy config file from one project into another. 作为选项,您可以发布构建事件并运行复制命令以将配置文件从一个项目复制到另一个项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM