John Bolter
asked on
Help with app.config in C# program
Hi, I am trying to merge common content external content into a single app.config. I cannot get it to work. Here is what I do
1. Start/Visual Studio 2013/etc and select new Console Application project
2. My source code looks like shown below and is saved at c:\John\ConsoleApplication 1 and directories underneath that.
My project app.config file looks like this
3. I create a sharedConfig1.config file as referenced above and place it in c:\john\consoleapplication 1. Its contents look like this
4. I compile and build the application. When I open up C:\John\ConsoleApplication 1\ConsoleA pplication 1\bin\Debu g\ConsoleA pplication 1.exe.conf ig is contains this
My question is why? Why doesn't it include the information in C:\John\ConsoleApplication 1\sharedCo nfig1.conf ig
According to http://msdn.microsoft.com/ en-us/libr ary/ms4043 00(v=vs.11 0).aspx I have done everything correctly. According to the MSDN link, it says "All linked configuration files are merged to form one file, similar to the behavior of the #include directive in C/C++". This is exactly what I want I just cannot get it to work.
All help or even ideas really welcome.
Thank you
John
1. Start/Visual Studio 2013/etc and select new Console Application project
2. My source code looks like shown below and is saved at c:\John\ConsoleApplication
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
}
}
}
My project app.config file looks like this
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<linkedConfiguration href="file://C:\John\ConsoleApplication1\sharedConfig1.config"/>
</assemblyBinding>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
3. I create a sharedConfig1.config file as referenced above and place it in c:\john\consoleapplication
<test1>
<test2>
<add key="test3" value="test4" />
</test2>
</test1>
4. I compile and build the application. When I open up C:\John\ConsoleApplication
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<linkedConfiguration href="file://C:\John\ConsoleApplication1\test.config"/>
</assemblyBinding>
<startup>
<supportedRuntime version="v4.0" sk[url="http://msdn.microsoft.com/en-us/library/ms404300(v=vs.110).aspx"]http://msdn.microsoft.com/en-us/library/ms404300(v=vs.110).aspx[/url]u=".NETFramework,Version=v4.5" />
</startup>
</configuration>
My question is why? Why doesn't it include the information in C:\John\ConsoleApplication
According to http://msdn.microsoft.com/
All help or even ideas really welcome.
Thank you
John
ASKER
HI, thanks, but that doesn't merge the XML config files which is what I want.
Basically I want the two XML config files to be merged like #include like is says in the MSDN documentation.
Does this not work
Basically I want the two XML config files to be merged like #include like is says in the MSDN documentation.
Does this not work
It does that on run-time I believe and puts in Debug folder. After you run, check your Debug folder to see if the combined App.config is there.
ASKER
Hi eghtebas, it can't do it at runtime because all the source code config files for merging aren't deployed. I have tested it too, and unless my code is bugged, the configuration files defined in the shared file aren't there.
Also according to this MSDN link http://msdn.microsoft.com/ en-us/libr ary/ms4043 00(v=vs.11 0).aspx it says All linked configuration files are merged to form one file, similar to the behavior of the #include directive in C/C++.
I just don't think it works. I have googled a lot and the only hits I get are other people not getting this to work either :-( Some people talk of something named fuslogvw and fusion only recognising this linkedConfiguration syntax, but that isn't written on the Microsoft website.
Also according to this MSDN link http://msdn.microsoft.com/
I just don't think it works. I have googled a lot and the only hits I get are other people not getting this to work either :-( Some people talk of something named fuslogvw and fusion only recognising this linkedConfiguration syntax, but that isn't written on the Microsoft website.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Saige, thank you again, this single answer has made my subscription to Experts Exchange worth the money.
From the documentation on MSDN, it is misleading. Although I think I now understand the purpose of <linkedConfiguration> from your feedback, I can also see to it isn't what I am looking.
Thank you!
From the documentation on MSDN, it is misleading. Although I think I now understand the purpose of <linkedConfiguration> from your feedback, I can also see to it isn't what I am looking.
Thank you!
ASKER
Thank you!
- never copy
- copy if newer
- always copy
If you select one of the last two, App.config should be copied to your Debug folder. Visual Studio never changes the original files (as far as I know). It changes them in compile time if directed to do so.
Mike