0

I have a parent application which has a config file that contains connection strings.

I would like all child applications I develop to be able to reference this config file so I only have to update connection strings in one place.

Parent Application web.config

<connectionStrings configSource="ConnectionStrings.config"/>

Parent Application ConnectionStrings.Config

<?xml version="1.0"?>
<connectionStrings>

    <add name="MyConnectionString" connectionString="Data Source=***;Initial Catalog=***;Integrated Security=False; Password=***;User ID=***" providerName="System.Data.SqlClient" />

</connectionStrings>

This works fine for bringing in data in the parent application.

I've added the ConnectionStrings.config file to my child application as a linked file and then reference it in the web.config as follows:

Child Application web.config

<connectionStrings configSource="ConnectionStrings.config"/>

But when I run the child application I get the following error:

Unable to open configSource file 'ConnectionStrings.config'. (C:\Child Application\web.config line 8)

Any ideas?

Thanks

Simon
  • 1,293
  • 5
  • 21
  • 39
  • Have you tried setting the build type to `content` and `copy to output directory` on the parent project's config file, and then referenced the file as `bin/ConnectionStrings.config`? – Gigabyte Jul 22 '16 at 16:40

2 Answers2

0

Under the child project, open the file properties of the linked ConnectionStrings.config file and set Copy To Output Directory to Copy always. You have to do this in order for this file to be copied to the child project bin directory regardless of the setting for the parent project ConnectionString.config file.

Larry
  • 511
  • 4
  • 10
0

You could also use project post build steps and copy configuration file into output directory.

maciejgos
  • 103
  • 1
  • 10