I’ve created a class library that contains three entity models for three databases that other classes have to connect to. This class library is then used by three different web services and a website. These are all installed on their own server so there’s no easy way to let them share the same connection data.
In my web.config files I have this line:
<connectionStrings configSource="Dependencies.ConnectionStrings.Config"/>
This will load the connection strings from a separate XML file. It works fine but it also means that I now have 5 different copies of this Dependencies.ConnectionStrings.Config file. I would prefer to use a single file during development.
However, my solution also contains four setup projects and in these setups, the config files must be next to each other.
So how do I tell VS to share a single config file between multiple projects yet without modifying web.config?
To make it slightly more complicated, the class library uses an app.config to store the connection strings. And I can’t tell app.config to link the connection strings to a separate config file, apparently…
One additional complication is that the connection strings need to be modified by the system administration after installation. That’s because it will have to look to a different database than the development databases. (Actually, during development, I use 3 databases to split up the entity logic. The Test and Production environments will just use a single database.)
My current solution is simple. I’ve added the Dependencies.ConnectionStrings.Config file to a separate folder in my solution and regularly drag&drop this into the other projects to update them. Although this works, it’s error-prone…
The big issue is you cannot have a linked config file in the folder hierarchy above the current main config file, which makes sharing them difficult.
Have you looked at placing this somewhere higher up the configuration hierarchy- perhaps in the root web.config or machine.config?
Another option is to have some pre build events build these files, so you don’t have to worry about having multiple copies of them. I’ve used the prebuild option quite successfully when I need to create a different connection string per developer.