Solved

Multiple app.config's

Posted on 2014-12-13
1
61 Views
Last Modified: 2015-01-27
Hi, earlier I asked this question on Experts Exchange and got a detailed and very satisfactory answer http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_28580184.html

I still have the underlying problem though.

My problem is I have a solution with 17 projects and each project has its own App.config. The content of the App.config for most of the projects is almost the same (all the projects that have a UI component have the same UI settings, or I would like them to), but I don't want to repeat the same things in every project and then when I update one project have to update all 17. When the solution builds I would like to merge together all the App.config's for each of the projects into a super single App.config for each project containing all the values.

I cannot see how to do this. All I know is you can't do this with <linkedConfiguration> and <configSource>, as shown below,  doesn't appear to work either.

Here is my test program

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
        }
    }
}

Open in new window


and here is it's App.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings configSource="c:\John\ConsoleApplication1\settingsDatabase.config"/>
  <appSettings configSource="c:\John\ConsoleApplication1\settingsUserInterface.config"/>
  <appSettings configSource="c:\John\ConsoleApplication1\settingsMail.config"/>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
</configuration>

Open in new window


The file settingsDatabase.config contains
<configuration> 
 <appSettings>
    <add key="test1" value="test2" />
    <add key="test2" value="test3" />
 </appSettings>
<configuration>

Open in new window


The file settingsUserInterface.config contains
<configuration> 
 <appSettings>
    <add key="test3" value="test4" />
    <add key="test5" value="test6" />
 </appSettings>
<configuration>

Open in new window


The file settingsMail.config contains
<configuration> 
 <appSettings>
    <add key="test7" value="test8" />
 </appSettings>
<configuration>

Open in new window


When I build and compile the application, the config file for my application doesn't change, C:\John\ConsoleApplication1\ConsoleApplication1\bin\Debug\ConsoleApplication1.exe.config contains the following

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings configSource="c:\John\ConsoleApplication1\settingsDatabase.config"/>
  <appSettings configSource="c:\John\ConsoleApplication1\settingsUserInterface.config"/>
  <appSettings configSource="c:\John\ConsoleApplication1\settingsMail.config"/>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
</configuration>

Open in new window


I want it to contain
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="test1" value="test2" />
    <add key="test2" value="test3" />
    <add key="test3" value="test4" />
    <add key="test5" value="test6" />
    <add key="test7" value="test8" />
  </appSettings>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
</configuration>

Open in new window


If someone can point me in the right direction how to get this working I would really appreciate it.

Thank you

John
0
Comment
Question by:John Bolter
1 Comment
 
LVL 33

Accepted Solution

by:
it_saige earned 500 total points
ID: 40498165
Historically problems of this type have been handled by many different ways (a couple of the common methods include):
1.  Creating a single 'Configuration' or 'Resources' project that contains all the resources and configuration settings in one project.
2.  Using a single static Xml file and building a helper class to read/write to the Xml file.

If neither of these methods will suit your needs, then perhaps an alternative approach would be to use the Microsoft Enterprise Library.

http://msdn.microsoft.com/en-us/library/ff664552%28v=pandp.50%29.aspx

-saige-
0

Featured Post

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C# parent child form 5 28
Hey Audio! 3 28
Moving code from one TFS branch to another 3 25
Getting error in connectionstring with Excel. 30 30
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…
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.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

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

17 Experts available now in Live!

Get 1:1 Help Now