Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Multiple app.config's

Posted on 2014-12-13
1
Medium Priority
?
82 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 35

Accepted Solution

by:
it_saige earned 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

926 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