Solved

Multiple app.config's

Posted on 2014-12-13
1
53 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 32

Accepted Solution

by:
it_saige earned 500 total points
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Article by: Ivo
Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

744 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

21 Experts available now in Live!

Get 1:1 Help Now