Solved

Multiple app.config's

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
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!
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 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