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

本文关键字:顺序 问题 脚本 | 更新日期: 2023-09-27 17:49:15

我尝试向我的脚本包添加一个自定义排序,如下所述。但是,在构建项目时,我得到以下错误:

错误1 '命名空间。AsIsBundleOrderer'没有实现接口成员"System.Web.Optimization.IBundleOrderer.OrderFiles (System.Web.Optimization.BundleContext,System.Collections.Generic.IEnumerable)

代码:

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);

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

您的方法签名与接口不对应。应该是这样:

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

注意不是IEnumerable<FileInfo>而是IEnumerable<BundleFile>