2015-07-12 189 views
3

我可以在我的Bundle.config文件中包含脚本吗,还是仅用于样式包?Bundle.config可以包含ScriptBundles吗?

<?xml version="1.0" encoding="utf-8" ?> 
<bundles version="1.0"> 
    <styleBundle path="~/Content/css"> 
    ... 
    </styleBundle> 
    <scriptBundle path="~/Scripts"> 

    Is this possible? 

    </scriptBundle> 
</bundles> 

而且任何人都可以提供一个链接到一个Bundle.config参考,解释可能的标签和结构?我已经搜索过,但我可以想出的是代码捆绑而不是标记的代码方式。我明白为什么 - 标记方式更旧,甚至可能会被弃用。但我想了解标记方式,因为它的通用方法是使用旧方法的遗留系统。

回答

3

这被称为“捆绑清单”。这是一个XML文件,位于~/bundle.config,并通过BundleManifest.ReadBundleManifest();加载到您的Application_Start中。

有一个XSD in CodePlex, named BundleManifestSchema.xsd

<?xml version="1.0" encoding="utf-8"?> 
<xs:schema id="BundleConfig" xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
    <xs:complexType name="include"> 
    <xs:attribute name="path" type="xs:string" use="required" /> 
    </xs:complexType> 

    <xs:complexType name="styleBundle"> 
    <xs:sequence> 
     <xs:element name="include" type="include" minOccurs="1" maxOccurs="unbounded" /> 
    </xs:sequence> 
    <xs:attribute name="path" type="xs:string" use="required" /> 
    <xs:attribute name="cdnPath" type="xs:string" use="optional" /> 
    </xs:complexType> 

    <xs:complexType name="scriptBundle"> 
    <xs:sequence> 
     <xs:element name="include" type="include" minOccurs="1" maxOccurs="unbounded" /> 
    </xs:sequence> 
    <xs:attribute name="path" type="xs:string" use="required" /> 
    <xs:attribute name="cdnPath" type="xs:string" use="optional" /> 
    <xs:attribute name="cdnFallbackExpression" type="xs:string" use="optional" /> 
    </xs:complexType> 

    <xs:element name="bundles"> 
    <xs:complexType> 
     <xs:choice minOccurs="0" maxOccurs="unbounded"> 
     <xs:element type="styleBundle" name="styleBundle" /> 
     <xs:element type="scriptBundle" name="scriptBundle" /> 
     </xs:choice> 
     <xs:attribute name="version" type="xs:string" /> 
    </xs:complexType> 
    </xs:element> 

</xs:schema> 

所以,是的,支持scriptBundle

2

don't think it's possible我想你应该避免使用XML符号。网络上几乎没有关于该主题的资源。因此,将XML重写为C#可能会更快。但是,有一个NuGet软件包,可以让您通过XML进行配置。该示例可在GitHubproject site上找到。

+0

CodeCaster的答案是更好的... – rocky

相关问题