App.Config

R

RedLars

Hi,

Have a question about an AppSetting's file in VS2005.

Under Assembly \ Properties I got a Settings.settings which contains a
table of name, type, value etc. I also got a App.Config file in the
assembly which mirror the values in the table. When building the app
it generates WindowsApplication1.exe.config which is a copy of
App.Config. However If I change the content of the
WindowsApplication1.exe.config file using notepad, say from
<add key="KEY" value="test" />
to
<add key="KEY" value="demo" />
and re-run the application (without rebuilding it) it does not use the
new value.

I'm using this code to retrive the data;

string s = ConfigurationManager.AppSettings.Get("KEY");

Whats the correct way of using an settings file with .NET 2.0 that a
user can edit manually ? Should I be using other resources and api?

Cheers
 
K

Kevin Spencer

The app.config file is used when developing the project, and is compiled
with the project to create the appname.exe.config file, which is used by the
app when running. The appname.exe.config file must be in the directory of
the exectuable's AppDomain, which is the directory the exe resides in. It
can be changed manually and will work after the app is deployed.

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
 
R

RedLars

Thanks for the feedback.

Say I have a solution with one .exe and 3-4 aseemblies and I want one
common config file. How would I go about setting that up?

I mean, in which component do I place the app.Config file so that all
components can access its' information?

Say the the project consists of Demo.exe, common.dll, foo.dll and
bar.dll and they all needs to read config information from one place
(App.config?). All are part of same solution. Sort of confuessed here
as youse might have noticed.

Appreciate any feedback.
 
K

Kevin Spencer

Hi RedLars,

In Visual Studio 2005, you can add Settings to each separate project. If
they exist in the executable Project, the values in the executable Project
will be used. I have done very similar types of projects myself.

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
 
R

RedLars

Thanks for the feedback.

Unfortunately my problem is not coming across right.

Say I create a solution and add four dll projects to the solution. If
I then add different settings to each project (project properties-
settings) and build the solution I get five libraryConfig.exe.config
files that mirror the individual settings in each project I created.
This is not acceptable for me, I'm looking for just one config file
for all the projects within the solution.

In addition, a requirement of the project is that the config file
should not depend on the .exe of the project to work (Dont want for
instance LibraryCommon.dll to depdent on Library.exe to read the
config file).

So how can I, using .NET and Visual Studio, create and maintain one
config file that all projects within a visual studio solution can
access and alter.
 
M

macleod

What about creating your own XML file and distributing it with the app.
That way any module can access it using standard .Net classes?
 
R

RedLars

Yeah, I'm definitely considering that. Initally I'd perfer using .NET
(i.e. not re-inventing the wheel) but now I'm not so sure.
 
M

M Irfan

Hi RedLars,

<LinkedConfiguration> that Kevin referred is certainly great but that
is specific .NET 3.0. I believe for the time being
"ExeConfigurationFileMap" in conjunction with
"OpenMappedExeConfiguration" can be helpful. Your dll components can
have their own configuration files and Exe application has its own.
You can load each components config settigs when it is first
instantiated. For simplicity you can create a seperate method in each
assembly that will load config settings and you can call this method
whenever module is laoded for the first time in memory.

Regards,
Irfan.
 
M

M Irfan

My apologies for making a wrong statement regarding
LinkedConfiguration. I felt sorry when after positng I read this:

"The way for application config file to include another config file,
is a feature we introduced in .Net 2.0. This is called
"linkedConfiguration".

Regards
Irfan.
 

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