Tool to generate strongly typed classes for configuration sections

Posted: Dec 04, 2006  9 comments  

Average Rating

Tags
Genscode
MWA

I wrote a simple tool to generate strongly typed classes for IIS configuration sections which can then be used with MWA to enable intellisense. This tool should be able to generate very logical intuitive type names in most cases. Generated code is similar to code samples in my earlier blog.

Usage:
genscode.exe <schemaFile> <optional section name>

This tool dumps the code on the console. Redirect to save in a file.
genscode.exe %windir%\system32\inetsrv\config\schema\IIS_Schema.xml system.webServer/httpCompression > HttpCompression.cs

Omitting section name will make it generate classes for all sections defined in schema file.
genscode.exe %windir%\system32\inetsrv\config\schema\IIS_Schema.xml > IISConfigSections.cs

Compile the generated code to build a library.
csc /t:library /r:Microsoft.Web.Administration.dll IISConfigSections.cs

Add this library to your project references or just copy-paste the generated code in your code which is using MWA and start editing IIS sections without referring to schema. Here is how adding caching profiles will look like.

using SystemwebServer;

ServerManager
sm = new ServerManager();

CachingSection cs = (CachingSection)sm.GetApplicationHostConfiguration().GetSection(
    CachingSection.SectionName,
    typeof(CachingSection));
cs.Profiles.Add(
    ".htm",
    EnumProfilesPolicy.CacheForTimePeriod,
    EnumProfilesKernelCachePolicy.CacheForTimePeriod,
    new TimeSpan(1000),
    EnumProfilesLocation.Downstream,
    "HEADER",
    "QUERYSTRING");

ProfilesCollection profiles = cs.Profiles;
ProfilesCollectionElement aspProfile = profiles.CreateElement();
aspProfile.Extension = ".asp";
aspProfile.Policy = EnumProfilesPolicy.CacheUntilChange;
profiles.Add(aspProfile);

sm.CommitChanges();

Attached: GenSCodeInstall.zip (containing installer GenSCodeInstall.exe which will install genscode.exe and configschema.dll).

-Kanwal

Attachment: GenSCodeInstall.zip

Comments

  1. Kanwaljeet Singla's Weblog
    December 4, 2006

    Download from http://blogs.iis.net/ksingla/archive/2006/12/04/tool-to-generate-strongly-typed-classes-for-configuration-sections.aspx

  2. Kanwaljeet Singla's Blog
    December 4, 2006

    Microsoft.Web.Administration (MWA) returns generic ConfigurationSection, ConfigurationElementCollection,

  3. TrackBack
    August 10, 2007
  4. TrackBack
    September 15, 2007
  5. IIS 7.0 Server-Side
    May 1, 2008

    The IIS 7.0 Resource Kit Book is finally out! Ok, it&rsquo;s been out for almost 2 months, but somehow

  6. Kanwaljeet Singla's Blog
    June 9, 2008

    MWA (Microsoft.Web.Administration) is pretty popular among developers who wish to read/write IIS configuration

  7. Kanwaljeet Singla's Weblog
    June 9, 2008

    MWA (Microsoft.Web.Administration) is pretty popular among developers who wish to read/write IIS configuration

  8. Kanwaljeet Singla's Blog
    June 15, 2008

    As promised in my previous post , I updated genscode tool to provide intellisense for AhAdmin code in

Submit a Comment