Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

App.config issue with many projects in same solution

I have a solution in visual studio 2010 which constists of 7 different projects. I want to keep some settings that is used by logic in project X in project X's app.config file. However if I create an app.config like the one below:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
     <add key="PrimaryEmail" value="[email protected]"/>
     <add key="CCEmail1" value="[email protected]"/>
  </appSettings>
</configuration>

and then in a class in project X uses code like this:

ConfigurationManager.AppSettings["PrimaryEmail"]

it can't find it and ConfigurationManager.AppSettings.Count returns 0.

However if I create the same app.config in the StartUp project Y of the solution it finds the data in that one.

Is it possible somehow to use the information in app.config in project X in this case? I guess it has to do soemthing with the fact that I have many projects in the same solution.

like image 259
Kneta_ Avatar asked Mar 21 '26 17:03

Kneta_


1 Answers

config file in Project X is available in Project X only. If your startup project is Y, then you need to have config file in this project. 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.

like image 111
realnero Avatar answered Mar 24 '26 05:03

realnero