Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 489
  • Last Modified:

Use one app.config for multiple exe files

I have created a solution in Visual Studio 2008 that has 5 console app projects. They call a common app.config. When I build them, each project creates it's own version of the app.config, called something like DataFTP.exe.config. If something changes I don't want to have to change all the config files. I don't see any settings in Visual Studio or by opening the .proj files in a text editor. Can anyone tell me how to do this?
Thanks,
0
asaworker
Asked:
asaworker
1 Solution
 
jasonduanCommented:
One way to workaround this is to use "build events"

From Visual Studio, right click the project, then "Properties", then "Build Events" tab, you can put copy command there.
0
 
asaworkerAuthor Commented:
What is the copy comand?
0
 
asaworkerAuthor Commented:
I see Pre-buid event command line, and also Post-build command line.
 How will the exe file know to use the common app.config, instead of the exe-specific file?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
morguloCommented:
You can use custom config file:

ExeConfigurationFileMap map = new ExeConfigurationFileMap();
map.ExeConfigFilename = "config.file";
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);

Open in new window

0
 
asaworkerAuthor Commented:
Do you mean those lines would go in the Pre-build event command line or Post-build command line fields?
0
 
asaworkerAuthor Commented:
I found http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.openmappedexeconfiguration.aspx, but I'm not sure what it means. Is this a class file that I include in each project? Does program.cs have to call this file?
0
 
asaworkerAuthor Commented:
I am using Framework 3.5
0
 
DivinityCommented:
If your problem is dat you want to use the same .config file for each console application once it has been compiled and is ready for use, then you should use morgulo's solution, which suggests a custom config file.

If however you don't care that each console application has it's own .config file, but you want to use the same file during development, you can do the following:
- Add the .config file to one of the console app projects.
- On the other four projects, right-click the project and choose "Add Existing Item".
- Browse to the .config file in the first project's folder and select it.
- Don't click "Add" but click the arrow next to it.
- Choose "Add as link" from the dropdown menu.
Now all projects use the same file when building the solution.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now