Attach and Access config file for Class Library

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

Is there a way in which we can attach a configuration file for a "Class
Library Project" and access its values dynamically.

I understand that Class Library would generate a .dll and cannot have other
configuration files. But can we add this "App.config" file as a "embedded
resource" and then access it?

I have used "ConfigurationSettings.AppSettings" and "AppSettingsReader",
but i am not able to achieve the result.

Appreciate your help
 
Mike Woodring's stuff might give you what you want

http://staff.develop.com/woodring/dotnet/#AssemblySettings

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

nntp://news.microsoft.com/microsoft.public.dotnet.framework/<[email protected]>

Hi,

Is there a way in which we can attach a configuration file for a "Class
Library Project" and access its values dynamically.

I understand that Class Library would generate a .dll and cannot have other
configuration files. But can we add this "App.config" file as a "embedded
resource" and then access it?

I have used "ConfigurationSettings.AppSettings" and "AppSettingsReader",
but i am not able to achieve the result.

Appreciate your help
--
IT Expert, R&D Department,
Hanwha S&C, Seoul

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.771 / Virus Database: 518 - Release Date: 28/09/2004



[microsoft.public.dotnet.framework]
 
Hi,

I have found myself in this situation and what I do is implement a
LoadConfig method inside the class needing it ( it may be a singleton for
more than one class or static members) and read a file expected in the app
location, parse it and assign a hashtable with the values/keys

Not the best solution, but it does work fine

cheers,
 
The way this is *supposed* to work, the app.config would hold the settings
for all DLLs in the app, and the dll would look to the same config file for
all settings, including the settings for the dll.

On the other hand, this is not always practical. I have a plug-in
architecture in one of my apps, and I need the config files to be specific
to the plug in.

For that purpose, I don't use the config file API. There isn't that much
there anyway.

Just create a simple XML file with the settings for your DLL, store it with
the name of "libraryname.xml" in the application folder (you can include it
in the setup), and have your app simply load the xml file from the
application folder. Use SelectSingleNode() to pick off specific settings.

I would recommend against using the XML file as a resource. The point of
the config file is that the system administrator can change the values in it
to reflect realities in the environment (connection strings, server
locations, database names, stored proc names, file locations, etc), without
requiring the developer to recompile. Placing the settings in a resource
requires a "recompile" of sorts to change any values.

(One advantage of not using the config file API: your app can change the
config file! This advantage will disappear with .NET Framework 2.0, BTW).

I hope this helps,
--- Nick
 
Back
Top