Solved

Use one app.config for multiple exe files

Posted on 2011-03-09
8
475 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

792 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