Asp.net mvc 4 如何配置MVC';s风格的捆绑订单?

Asp.net mvc 4 如何配置MVC';s风格的捆绑订单?,asp.net-mvc-4,bundling-and-minification,Asp.net Mvc 4,Bundling And Minification,我的web应用程序正在使用带有jquery ui和jqgrid的大型图标集。 为了在升级jQueryUI或jqgrid时方便地维护对CSS的更改以适应更大的图标,我有一个单独的CSS文件,其中有一系列覆盖 可以想象,这个覆盖文件必须包含在jQueryUI样式表和jqgrid样式表之后 我把我所有的样式表像这样放在一个包里 bundles.Add(new StyleBundle("~/Content/dark-hive/allstyles").Include( "~/Content/dar

我的web应用程序正在使用带有jquery ui和jqgrid的大型图标集。
为了在升级jQueryUI或jqgrid时方便地维护对CSS的更改以适应更大的图标,我有一个单独的CSS文件,其中有一系列覆盖

可以想象,这个覆盖文件必须包含在jQueryUI样式表和jqgrid样式表之后

我把我所有的样式表像这样放在一个包里

bundles.Add(new StyleBundle("~/Content/dark-hive/allstyles").Include(
    "~/Content/dark-hive/jquery-ui-1.8.23.custom.css",
    "~/Content/ui.jqgrid.css",
    "~/Content/jquery-ui-fixes.css",
    "~/Content/icons.css",
    "~/Content/site.css"));
但事实是这样的

<link href="/Content/dark-hive/jquery-ui-1.8.23.custom.css" rel="stylesheet"/>
<link href="/Content/jquery-ui-fixes.css" rel="stylesheet"/>
<link href="/Content/ui.jqgrid.css" rel="stylesheet"/>
<link href="/Content/icons.css" rel="stylesheet"/>
<link href="/Content/site.css" rel="stylesheet"/>

如何配置包以正确的顺序呈现

更新
好吧,这是愚蠢的,但它的工作

无论我做什么,这些文件都会呈现错误。所以我尝试了一些愚蠢的方法,首先添加jquery-ui-fixes.css,最后添加jquery-ui-1.8.23.custom.css

突然我点的菜坏了

<link href="/Content/jquery-ui-fixes.css" rel="stylesheet"/>
<link href="/Content/dark-hive/jquery-ui-1.8.23.custom.css" rel="stylesheet"/>
<link href="/Content/ui.jqgrid.css" rel="stylesheet"/>
<link href="/Content/icons.css" rel="stylesheet"/>
<link href="/Content/site.css" rel="stylesheet"/>

我将我的javascript文件重命名为jqueryuifixes.css,现在它的顺序保留在较低的js文件中

我认为如果一个样式表的名称中有一个-的话,出于某种原因,它会首先得到优先排序,并且它的顺序会与其他包含一个-的文件一起维护


如果有人能解释这一点,我会给他们支票。

如果您单独包含每个文件,捆绑包将尊重您的订单

var bundle = new Bundle("~/Content/dark-hive/allstyles", new StyleBundle());           
bundle.Include("~/Content/dark-hive/jquery-ui-1.8.23.custom.css");
bundle.Include("~/Content/ui.jqgrid.css");
bundle.Include("~/Content/jquery-ui-fixes.css");
bundle.Include("~/Content/icons.css");
bundle.Include("~/Content/site.css");
bundles.Add(bundle);
更新

即使使用显式排序,您也会发现有一个相当方便的内置排序系统,它首先对特定命名的文件进行排序。要完全清除此问题,您可以使用:

bundles.FileSetOrderList.Clear();
您还可以使用以下方式添加自己的定制订单:

BundleFileSetOrdering ordering = new BundleFileSetOrdering("My Order");
ordering.Files.Add("jquery.js");

bundles.FileSetOrderList.Clear();
bundles.FileSetOrderList.Add(ordering);

本质上,有一个庞大的内置文件列表,它将以特定的顺序排在列表之外的任何文件之前,但这些选项让您可以控制它。

您可以创建自定义绑定器并覆盖OrderFiles方法

public class CustomBundleOrderer : IBundleOrderer
{
    public IEnumerable<FileInfo> OrderFiles(BundleContext context, IEnumerable<FileInfo> files)
    {
        return files;
    }
}

顺序仍然不正确,我认为我使用的优化dll的版本可能有问题。我已经测试过了,而且有优先的内部顺序在起作用,即使手动按顺序添加文件。找到它-有一个特定文件的大列表以特定的顺序内置-但您可以覆盖它。答案更新。谢谢!文件的自动重新排序非常不直观。此答案为我抛出了一个错误:
System.Web.Optimization.StyleBundle不包含一个构造函数,该构造函数接受0个参数,这是System.Web.Optimization.Bundle.Bundle(string,string)的最佳重载方法匹配项具有一些无效参数参数2:无法从System.Web.Optimization.StyleBundle转换为字符串
IBundleOrderer的签名已更改。公共IEnumerable OrderFiles(BundleContext,IEnumerable文件){return files;}
var bundle = new StyleBundle("~/Content/dark-hive/allstyles")
{
    Orderer = new CustomBundleOrderer()
};

bundle.Include(
    "~/Content/dark-hive/jquery-ui-1.8.23.custom.css",
    "~/Content/ui.jqgrid.css",
    "~/Content/jquery-ui-fixes.css",
    "~/Content/icons.css",
    "~/Content/site.css");

bundles.Add(bundle);