Here is my xml structure:
<reco>
<styleSheets>
<group>
<asset source="~/Script/file1.css"/>
<asset source="~/Script/file2.css"/>
<asset source="~/Script/file3.css"/>
</group>
</styleSheets>
<scripts>
<group>
<asset source="~/Content/file1.js"/>
<asset source="~/Content/file1.js"/>
<asset source="~/Content/file1.js"/>
</group>
</scripts>
Here is my code:
public class AssetConfigurationElement : ConfigurationElement
{
/// <summary>
/// Gets or sets the source.
/// </summary>
/// <value>The source.</value>
[ConfigurationProperty("source", IsRequired = true, IsKey = true)]
public string Source
{
get
{
return (string)this["source"];
}
set
{
this["source"] = value;
}
}
}
public class GroupConfigurationElementCollection : ConfigurationElementCollection
{
public GroupConfigurationElementCollection()
{
AddElementName = "asset";
}
/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>The name.</value>
[ConfigurationProperty("name", IsRequired = true, IsKey = true, IsDefaultCollection = true)]
public string Name
{
get
{
return (string)this["name"];
}
set
{
this["name"] = value;
}
}
/// <summary>
/// Gets or sets a value indicating whether this <see cref="WebAssetGroupConfigurationElement"/> is enabled.
/// </summary>
/// <value><c>true</c> if enabled; otherwise, <c>false</c>.</value>
[ConfigurationProperty("enabled", DefaultValue = true)]
public bool Enabled
{
get
{
return (bool)this["enabled"];
}
set
{
this["enabled"] = value;
}
}
/// <summary>
/// Gets or sets the version.
/// </summary>
/// <value>The version.</value>
[ConfigurationProperty("version")]
public string Version
{
get
{
return (string)this["version"];
}
set
{
this["version"] = value;
}
}
/// <summary>
/// Gets or sets a value indicating whether this <see cref="WebAssetGroupConfigurationElement"/> is compress.
/// </summary>
/// <value><c>true</c> if compress; otherwise, <c>false</c>.</value>
[ConfigurationProperty("compress", DefaultValue = true)]
public bool Compress
{
get
{
return (bool)this["compress"];
}
set
{
this["compress"] = value;
}
}
/// <summary>
/// Gets or sets a value indicating whether this <see cref="WebAssetGroupConfigurationElement"/> is combined.
/// </summary>
/// <value><c>true</c> if combined; otherwise, <c>false</c>.</value>
[ConfigurationProperty("combined", DefaultValue = true)]
public bool Combined
{
get
{
return (bool)this["combined"];
}
set
{
this["combined"] = value;
}
}
protected override ConfigurationElement CreateNewElement()
{
return new AssetConfigurationElement();
}
protected override object GetElementKey(ConfigurationElement element)
{
return ((AssetConfigurationElement)element).Source;
}
}
public class SharedGroupConfigurationSection : ConfigurationSection
{
/// <summary>
/// Gets the style sheets.
/// </summary>
/// <value>The style sheets.</value>
[ConfigurationProperty("styleSheets")]
[ConfigurationCollection(typeof(GroupConfigurationElementCollection), AddItemName = "group")]
public GroupConfigurationElementCollection StyleSheets
{
get
{
return (GroupConfigurationElementCollection)base["styleSheets"] ?? new GroupConfigurationElementCollection();
}
}
/// <summary>
/// Gets the style sheets.
/// </summary>
/// <value>The style sheets.</value>
[ConfigurationProperty("scripts")]
[ConfigurationCollection(typeof(GroupConfigurationElementCollection), AddItemName = "group")]
public GroupConfigurationElementCollection Scripts
{
get
{
return (GroupConfigurationElementCollection)base["scripts"] ?? new GroupConfigurationElementCollection();
}
}
}
Is this configuration even possible? If so, what am i doing wrong?
I get this error message when i try to get the section with the configuration manager.
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.Parser Error Message: Unrecognized element ‘asset’.
Source Error:
Line 96:
Line 97:
Line 98:
Line 99:
Line 100:Source File: D:\ASP.NET Projects\Resource-Compiler\ResourceCompiler\Examples\web.config Line: 98
I was able to get it working. I had to add two new collections for the styleSheet node and the script node. Here is my complete code: