Saturday, September 24, 2016

When NuGet puts stuff into my Web.config for a library, what is it up to?

The ConfigurationSection class in/at System.Configuration.ConfigurationSection allows configurations to be handed into your .dll from the Web.config of another project. Make your own class which inherits from ConfigurationSection. Let's say it's called InData. Then...

<section name="foo" type="MyApp.MyFolder.InData" />

 
 

...goes in configSections in the Web.config and this goes outside configSections...

<foo bar="baz" />

 
 

InData itself looks like...

public class InData : ConfigurationSection
{
   [ConfigurationProperty("bar", DefaultValue="qux", IsRequired=false)]
   public string Bar
   {
      get { return (String)this["bar"]; }
      set { this["bar"] = value; }
   }

No comments:

Post a Comment