Hi TS,
From your description, you're using some class library projects in a Visual
studio 2005 solution and want to define some data/values in class library's
app.config file so as to reuse them in any upper level application which
reference the class library, correct?
Based on my understanding, for app.config file, .net framework application
only support using app.config file at application level at runtime. In
other words, only an application(exe) can use app.config file, for class
library component(dll), the app.config it reference is the one of the
application which load that class library assemblies. (So there is no
dedicated configuration file for assemby/dll at runtime).
However, why does VS 2005 allow us to add "app.config" file in class
library project? This is due to the following purpose:
In original class library(vs.net 2003), you can not define some values that
be shared with calling application and be able to overwrite/customize them.
Now, you can create setting items in the VS 2005 class library's project
"Settings" collection. To add/manage settings, you go through the following
steps:
**open project properties dialog
**choose "settings" tab in left
** in right panel, you can add multiple settings items(of various type)
After you add items and save it, you can find that the setting items are
actually saved/persisted in the app.config file in the class library
project.
Thus, when you reference this class library in any other application
project, the settings of the project(default value) will be automatically
available, and if you want to override/customize these settings in the
calling application project, you will need to copy the XML configuration
fragment in class library's app.config to your calling application's
app.config (and modify the certain value you want to customize) e.g.
#this is a typical setting persistent content in class library app.config,
you can copy them to calling application's app.config file and customize
any item's value
==============
<configSections>
<sectionGroup name="applicationSettings"
type="System.Configuration.ApplicationSettingsGroup, System,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="ClassLibrary1.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"
/>
</sectionGroup>
</configSections>
<applicationSettings>
<ClassLibrary1.Properties.Settings>
<setting name="ClassLibrarySetting1" serializeAs="String">
<value>setting1 value</value>
</setting>
<setting name="ClassLibrarySetting2" serializeAs="String">
<value>setting2 value</value>
</setting>
</ClassLibrary1.Properties.Settings>
</applicationSettings>
===============================
For your scenario, you can consider define the values you want to share to
calling application in class library's settings collecction. Also, by
default "Settings" collection is marked as "internal", you can manually
change the accessor from "internal" to "public" in the code file so that
calling application can directly acccess them. e.g.
string value1=
ClassLibrary1.Properties.Settings.Default.ClassLibrarySetting1;
Here is a former thread also discussing on the similar question:
http://groups.google.com/group/microsoft.public.dotnet.framework.webservices
/browse_thread/thread/c81a49ae2398f7b8/2f734c0f0d010cd1
Hope this helps some.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.