Thursday, September 23, 2010

How to add a configuration file to your class library

I have a web project with some configuration settings in the web.config. I added a class library to the project and realized I could not access those values from the class library. The solution is to add an app.config file to the class library project and copy the configuration settings from the web.config to the app.config.

To access ConfigurationManager from the class library, I need to add a reference to the System.Configuration .Net assembly.

If you don't like having the settings in both places, you could retrieve the configuration values for the web application by using the class library (app.config), and remove the configuration values from the web.config.


No comments:

Post a Comment