脚本捆绑问题 - 正确的顺序

时间:2014-03-08 23:23:12

标签: c# asp.net asp.net-mvc bundle

我尝试按照here所述向我的脚本包添加自定义排序。但是,在构建项目时出现以下错误:

  

错误1'Namespace.AsIsBundleOrderer'未实现接口   会员   “System.Web.Optimization.IBundleOrderer.OrderFiles(System.Web.Optimization.BundleContext,   System.Collections.Generic.IEnumerable)'

CODE:

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



public class BundleConfig
{
    // For more information on bundling, visit http://go.microsoft.com/fwlink/?LinkId=301862
    public static void RegisterBundles(BundleCollection bundles)
    {
        var bundle = new ScriptBundle("~/bundles/js").Include(
            "~/Scripts/jquery.min.js",
            "~/Scripts/jquery-ui.min.js",
            "~/Scripts/bootstrap.min.js",
            "~/Scripts/jquery.flot.categories.js",
            "~/Scripts/jquery.flot.js",
            "~/Scripts/jquery.flot.min.js",
            "~/Scripts/jquery.flot.orderBars.js",
            "~/Scripts/jquery.flot.pie.js",
            "~/Scripts/jquery.flot.resize.js",
            "~/Scripts/graphtable.js",
            "~/Scripts/fullcalendar.min.js",
            "~/Scripts/chosen.jquery.min.js",
            "~/Scripts/autoresize.jquery.min.js",
            "~/Scripts/jquery.autotab.js",
            "~/Scripts/jquery.jgrowl_minimized.js",
            "~/Scripts/jquery.dataTables.min.js",
            "~/Scripts/jquery.stepy.min.js",
            "~/Scripts/jquery.validate.min.js",
            "~/Scripts/jquery.cookie.js",
            "~/Scripts/raphael.2.1.0.min.js",
            "~/Scripts/justgage.1.0.1.min.js",
            "~/Scripts/glisse.js",
            "~/Scripts/styleswitcher.js",
            "~/Scripts/moderniz.js",
            "~/Scripts/jquery.sparkline.min.js",
            "~/Scripts/slidernav-min.js",
            "~/Scripts/jquery.fancybox.js",
            "~/Scripts/main.js",
            "~/Scripts/application.js",
            "~/Scripts/excanvas.min.js",
            "~/Scripts/float.settings.infobox.js"
        );

        bundle.Orderer = new AsIsBundleOrderer();
        bundles.Add(bundle);

1 个答案:

答案 0 :(得分:9)

您的方法签名与界面不对应。它应该是这样的:

public virtual IEnumerable<BundleFile> OrderFiles(BundleContext context, IEnumerable<BundleFile> files)
{
    return files;
}

请注意,它不是IEnumerable<FileInfo>,而是IEnumerable<BundleFile>