Solved

Use one app.config for multiple exe files

Posted on 2011-03-09
8
470 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
 
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

705 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

19 Experts available now in Live!

Get 1:1 Help Now