How does ConfigurationManager merge or build configurations for a referenced project?

Saturday, May 3, 2014

Suppose I have a C# class library project with an app.config file and I reference it an ASP.NET project that has a web.config file. Suppose I have a key in my web.config AppSettings called SmtpServerHostname. If I need the SmtpServerHostname in my referenced class library as well, how should I handle configuring the configuration files? Specifically,

  1. If I don't define the SmtpServerHostname key in my class library, will that "pass through" because it is being referenced by another project where it is defined?

  2. If I do define the key in my class library, which one will take precedence?

  3. I currently make use of web.config transforms when publishing my application. Is it possible to transform the app.config file similarly?