using an app.config of a referenced project

T

TS

I cannot get this to work. I added an app.config to a project i reference
from my web application project (vs 05) but can see no way to access the
settings within it.

the other thing is that I expected this config file (.dll.config) to get put
in my web app's bin folder along with it's .dll file when i did a build, and
that didnt' happen either.

do I have access to the app.config in my project or is it worthless? If so
why can i add an app.config?

thanks
 
S

Steven Cheng[MSFT]

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.
 
S

Steven Cheng[MSFT]

Hi TS,

Have you got any further idea on this thread or does the suggestion in my
last reply helps you some? If there is anything else we can help, please
feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

Steven Cheng[MSFT]

Thanks for your reply TS,

For the broken reference link, it actually point to the MSDN docuemnt on
the .NET 2.0/VS 2005 project's Application Settings. However, it still
doesn't include description on how to share the settings/properties in
class library project to the host application that reference the class
librarry asembly.

#Application Settings
http://msdn2.microsoft.com/en-us/library/a65txexh(VS.80).aspx

#Application Settings Overview
http://msdn2.microsoft.com/en-us/library/k4s6c3a0.aspx

My last reply and the messages in those former threads have described this.

If you have any further questions on this or any paricular things unclear,
please feel free to let me know.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

Steven Cheng[MSFT]

Please feel free to let me know if you have anything else wonder on the
related configuration or management approach.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 

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

Members online

Forum statistics

Threads
473,995
Messages
2,570,233
Members
46,821
Latest member
AleidaSchi

Latest Threads

Top