Solved

Use one app.config for multiple exe files

Posted on 2011-03-09
8
472 Views
Last Modified: 2012-08-13
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
Comment
Question by:asaworker
8 Comments
 
LVL 11

Expert Comment

by:jasonduan
ID: 35087854
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
 

Author Comment

by:asaworker
ID: 35088204
What is the copy comand?
0
 

Author Comment

by:asaworker
ID: 35088221
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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 5

Expert Comment

by:morgulo
ID: 35088396
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
 

Author Comment

by:asaworker
ID: 35088446
Do you mean those lines would go in the Pre-build event command line or Post-build command line fields?
0
 

Author Comment

by:asaworker
ID: 35088519
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
 

Author Comment

by:asaworker
ID: 35088764
I am using Framework 3.5
0
 
LVL 5

Accepted Solution

by:
Divinity earned 500 total points
ID: 35093628
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now