How to reference an external config file in app.config

K

Kevin Spencer

Hi Benjamin,

According to the .Net SDK, the "file" attribute is indeed an optional
attribute of the appSettings section. In addition, the appSettings section
and a number of other sections can use an optional "configFile" attribute to
specify an external configuration file. The rules for the "configFile" and
"file" attributes differe slightly, however. Here is a reference to the
appSettings section and the "file" attribute:

http://msdn2.microsoft.com/en-us/ms228154.aspx

Here is documentation for the "configSource" attribute:

http://msdn2.microsoft.com/en-us/system.configuration.sectioninformation.configsource.aspx

You may note that you can now set the "RestartOnExternalChanges" attribute
when using the configSource attribute.

Be sure that you get all the syntax correct. It is probable that the syntax
may be slightly different than with .Net 1.1, and it is almost certain that
the syntax rules are more strict!

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

I recycle.
I send everything back to the planet it came from.
 
G

Guest

Thanks!

It is a good start, but a way to go to have the same flexibility as using
the obsolete <appSettings file="YourSettings.config"> because as you can read
at my linked web page the additions or overrides in YourSettings.config are
merged into app.config only IF (!) YourSettings.config exists, otherwise are
only the values in the app.config used. This dynamic is exactly what I want
to achive but instead using the preferred applicationSettings/My.MySettings
section.

I have valuated the information that you areis not at all used, even if a
specific item is not included in the YourSettings.config that exists in
app.config. configSource seems to be a more ALL or NOTHING approach.

Comment?
 
G

Guest

I did loose some words in my sentence. Let me explain what I really want to
achive.

We have app.config file that has the URL to the web service, this file is
checked in into our file/version control system. And this is the URL that is
used from all installed clients around the world.

<applicationSettings configSource="CesowWindowsClient.User.config">
<My.MySettings>
<setting name="WebService" serializeAs="String">
<value>http://<SERVER>/Service.asmx

But we that develops the solution we want to access the web service on our
localhost instead of the server.

<setting name="CesowWindowsClient_CesowFacade_Service"
serializeAs="String">
<value>http://localhost/Service.asmx</value>
</setting>

But we do not want to checkout/edit the app.config file to make it work for
the developers. It should be like that, if a configfile exists on a specific
place on the hard drive, these settings should override the settings in the
standard app.config.
E g app.config

<applicationSettings configSource="C:\CesowWindowsClient.User.config">
<My.MySettings>
<setting name="WebService" serializeAs="String">
<value>http://<SERVER>/Service.asmx

And C:\CesowWindowsClient.User.config haves the localhost URL above.

But I can not make this work.
 
G

Guest

Did you ever find a way of doing this?

I know in <appSettings> it is possible using the file="fileName.config"
attribute, but the current project is making use of .NET 2.0's
<applicationSettings> instead.

I can't, however find an equivalent to the <appSettings>'s file attribute in
<applicationSettings>.

Thanks,
Andre
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top