これが私の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