简体   繁体   中英

.NET and Configuration Files With DLLS

I am somewhat familiar with using configuration in .NET, but I am a little bit confused about something. You create an App.Config file to go with your exe, and any dlls you create use the same configuration file.

So how do you access the config in the configuration file from within your DLL? If you create a settings.settings inside the DLL project in Visual Studio it ends up blank with no settings in it.

Thanks.

You can use the System.Configuration.ConfigurationManager class to get the settings from the app.config (or web.config) from within a DLL. The AppSettings property will get the data from the appSettings section of the config file.

NameValueCollection settings = System.Configuration.ConfigurationManager.AppSettings;
string keyValue = settings["SomeKey"];

I think you have to share the application settings file for all of your dlls.

So you must have a different section inside this config file for each referenced assembly...

There's no easy way to do what you are asking (use the app.config file from your DLL project rather than or in addition to the app.config file for the EXE file that is using the DLL.)

See post #3 from this thread:

http://bytes.com/topic/c-sharp/answers/226001-problem-app-config-dll

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM