这是我的xml结构:
<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>
这是我的代码:
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();
}
}
}
这种配置甚至可能吗?如果是这样,我做错了什么?
当我尝试使用配置管理器获取该部分时,我收到此错误消息。
配置错误描述:处理服务此请求所需的配置文件期间发生错误。请查看下面的具体错误详细信息并适当地修改您的配置文件。
解析器错误消息:无法识别的元素“资产”。
源错误:
第 96 行: 第 97 行: 第 98 行: 第 99 行: 第 100 行:
源文件:D:\ASP.NET Projects\Resource-Compiler\ResourceCompiler\Examples\web.config 行:98