0

I am working on a solution that has multiple projects.

I follow the method described here (the first response that suggest using a common solution item): single app.config multi-project c#

The result is that for each project, the app.config file is copied and renamed like XXX.exe.config.

However, the desirable output is that the config file name remain the same (e.g. App.config) for each project. Because I wanted to put all the executable and the DLLs in the same folder when it's deployed (some executable reference to the same DLL so it make sense to put them all together).

Any suggestion is appreciated.

one noa
  • 345
  • 1
  • 3
  • 10
Johnyy
  • 2,056
  • 3
  • 22
  • 28
  • 3
    Why do you need a copy of the same configuration file for each project? Why not read your values into one project and have that project share those values publicly, making them available to other projects? – Bernard Nov 10 '11 at 14:30
  • @Bernard. In production environments, driving settings from config files (and having multiple config files and shared config settings) makes a lot of sense. I am working on a project with over 30 service projects (Web and Win-hosted WCF) and the number of common settings was driving us mad (until we changed them all to use TT files). – iCollect.it Ltd Nov 10 '11 at 14:41

2 Answers2

1

You can load a configuration file manually. See the discussion here: Using ConfigurationManager to load config from an arbitrary location

Community
  • 1
  • 1
ElDog
  • 1,230
  • 1
  • 10
  • 21
1

I suggest you look at using TT templating. Then the simple solution is to have an App.tt file that includes a common ttinclude file. This will generate an App.config file with the same (or different) content based on other settings you may want to set in the app.config.

For example we have an App.Config that looks like this:

<# EnvironmentName = "local"; #>
<#@ include file="App.Template.ttinclude" #>

The App.Template.ttinclude contains everything we want to output (along with some settings that change based on the Environment value as we support 8 installation enviromments.

Each App.Template.ttinclude actually includes another master config file that contains our common settings, but that starts to get complicated as we include environment-specific configs within the master config file, in a switch statement (to get around a bug in TT file processing).

Where we have an app specific DLL config, it simply includes one of our others:

e.g. MyApp.Exe.config contains:

<#@ include file="App.tt" #>
iCollect.it Ltd
  • 92,391
  • 25
  • 181
  • 202