Solved

Multiple app.config's

Posted on 2014-12-13
1
75 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 34

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

617 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