Matt
Matt

Reputation: 27011

Abstracting out common parts of solution projects' config files

I have a solution with 20 or so projects in it. Most of these projects' config files share large segments of their config files. So let's say they all share this bit of (ugly) code:

<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter,
Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, 
PublicKeyToken=31bf3856ad364e35" 
template="Timestamp: {timestamp}
Machine: {machine}
Identity Name: {identityName}
Authentication Type: {authenticationType}
Is Authenticated: {isAuthenticated}
Category: {category}
Process Name: {processName}
Process Id: {processId}
Severity: {severity}
EventId: {eventid}
Application Domain: {appDomain}

Session Id: {sessionId}
Class Name: {className}
Method Name: {methodName}
Thread Name: {threadName}
Extended Properties: {dictionary({key} - {value} )}

Title

{title}

Message

{message}

Stack Trace

{stackTrace}" name="Email Formatter"/>

What I am wondering, is there a Gulp-like process for .config files where common parts of files can be named and stored in another file, which then at build are pasted into the individual projects rendered config files?

Upvotes: 0

Views: 38

Answers (2)

Paul Carroll
Paul Carroll

Reputation: 1887

We have about 65 projects in our solution and share exactly the same problem. The solution that has worked very well for us is to make use of custom config sections and use external config files. These files are centralised under a folder (at the level of the project folders) called _MasterConfigs.

Each project uses a prebuild event to copy the configs it needs, and they are excluded from source control in those projects.

You reference files externally by using something like this (an example from one of our configs):

<solrConnections configSource="solr-local.config" />

Upvotes: 1

Vitaliy Nesterenko
Vitaliy Nesterenko

Reputation: 358

What about using config inheritance?

For web config there is info here.

For app config you can create common config file in a solution directory and reuse it in client app config like that:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings file="..\base.xml.config">
  ...
</configuration>

Upvotes: 2

Related Questions