1

I have a Core class lib which has all my logic inside.

I have a Web Application that uses IIS.

I have a Console Application that uses Http Listener.

Both host projects reference the Core lib that has a connectionStringSource.config file in it.

The hosts projects have used Add As Link to the connectionStringSource.config in Core and set to Copy To Output. In the web.config in the IIS host project it has

<connectionStrings configSource="bin\connectionStringSource.config"></connectionStrings>

However I get:

[ArgumentException: Illegal characters in path.]
[ConfigurationErrorsException: The configSource attribute is invalid.: Illegal characters in path. (line 13)]

If I change to

<connectionStrings configSource="bin/connectionStringSource.config"></connectionStrings>

It says

The configSource attribute must be a relative physical path, so the '/' character is not allowed.

Is there a way to share these settings?

I have followed the suggestions here and here but they don't seem to work.

Marcos Dimitrio
  • 6,651
  • 5
  • 38
  • 62
Jon
  • 38,814
  • 81
  • 233
  • 382
  • So you have one solution with three projects? – Matija Grcic Jul 09 '14 at 16:25
  • Can you set the link as "content" instead, and not reference it in the bin folder? Admittedly this is working around the problem rather than fixing it though! – Simon Jul 09 '14 at 17:06
  • @Jon I've had a similar problem before and solved it. Give me a minute to remember in which project. – Matija Grcic Jul 09 '14 at 17:17
  • It took me some time to remember that I've edited *.csproj, please report if this is working for you. I've tested it and it seems ok. – Matija Grcic Jul 09 '14 at 17:41

2 Answers2

7

Add your connections.config file to SolutionItems solution folder

enter image description here

In my case it contains

<connectionStrings>
  <add name="MyContext"
       connectionString="Data Source=Server\NamedInstance;Initial Catalog=MyDB;Integrated Security=True;MultipleActiveResultSets=True"
    providerName="System.Data.SqlClient" />
</connectionStrings>

Click on any project and edit the app.config or web.config

<connectionStrings configSource="connections.config"></connectionStrings>

Now click on project and choose Add existing item then add the connections.config as a link by clicking on Add as Link.

enter image description here

Now right click on the project and choose Unload project

enter image description here

Now click on the project and choose Edit project

enter image description here

You will see the following:

  <ItemGroup>
        <None Include="..\connections.config">
          <Link>connections.config</Link>
        </None>
        <None Include="App.config" />
      </ItemGroup>

To be able to reference this file we need to say to copy linked content files to scroll to the bottom and add

 <Target Name="CopyLinkedContentFiles" BeforeTargets="Build">
    <Copy SourceFiles="%(Content.Identity)" DestinationFiles="%(Content.Link)" SkipUnchangedFiles="true" OverwriteReadOnlyFiles="true" Condition="'%(Content.Link)' != ''" />
  </Target>

Reload the project.

enter image description here

Repeat for the projects you need to share the connections.config.

You can have a connections.release.config. Then in your Web.Release.config just add

 <connectionStrings xdt:Transform="SetAttributes" configSource="connections.release.config" />
Matija Grcic
  • 12,963
  • 6
  • 62
  • 90
1

Turns out there is a bug with Host.Owin.IIS which I logged here https://github.com/aspnet/Home/issues/95

Jon
  • 38,814
  • 81
  • 233
  • 382