这些 js 和 css 文件如何从我的项目中排除?

How can these js and css files be excluded from my project?

这些文件自动捆绑在 MVC 项目中。我在 VS 2013 中创建了一个新的 MVC 测试项目并验证了下面列出的项目,而不是在 BundleConfig 中明确添加的项目,它们在 bundles.Add() 方法中列出的项目之前自动包含在捆绑包中。

在 BundleConfig 的 RegisterBundles() 方法的第一行设置断点会在其他明确列出的文件添加到捆绑包之前按文件顺序显示它们。奇怪的是,捆绑包的数量是 0,但文件顺序中列出了 7 个。这也支持了它们是由 Visual Studio "behind the scenes" 添加的事实,因为这些文件在 C# 代码中添加的文件之前就已经存在了。

其中大部分未在 BundleConfig 中列出,也未使用 IE 的开发人员工具显示在网络 activity 中。不过,它们似乎应该出现在网络流量中。如果有人知道,我会对他们为什么不出现的解释感兴趣。

在下面方法的第一行调用 bundles.Clear() 并没有删除包含的 Visual Studio,即使这是 Clear() 的意图。看来微软决定不应该清除它们。

这些可能无法删除,但我想看看是否有人知道如何删除。我们的生产应用程序不需要所有这些,如果可能的话,我想省略一些。

   public class BundleConfig
{
    // For more information on bundling, visit http://go.microsoft.com/fwlink/?LinkId=301862
    public static void RegisterBundles(BundleCollection bundles)
    {
        bundles.Clear();

        bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                    "~/Scripts/jquery-{version}.js"));

        // Use the development version of Modernizr to develop with and learn from. Then, when you're
        // ready for production, use the build tool at http://modernizr.com to pick only the tests you need.
        //bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                 //   "~/Scripts/modernizr-*"));

        bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
                  "~/Scripts/bootstrap.js",
                  "~/Scripts/respond.js"));

        bundles.Add(new StyleBundle("~/Content/css").Include(
                  "~/Content/bootstrap.css",
                  "~/Content/site.css"));

    }
}

在上面的 C# 中显式添加其他文件之前的捆绑包中:

开发人员工具中列出的文件不包括上面的大部分文件:

这些不属于您的捆绑包。您正在查看 BundleCollection.FileSetOrderList Property 其中:

Gets a list that specifies default file orderings to use for files in the registered bundles.

如您所述,捆绑包计数为 0。不会添加这些文件 "behind the scenes" 除非您明确将它们包含在您的捆绑包中。幕后发生的事情是,当捆绑发生时,这些文件将在您自己的文件之前排序。不过,如果需要,您也可以指定自己的顺序。

重新订购捆绑包是 bundling/minification 功能的一部分。还有更多细节,包括定义排序的代码 in this SO question and answer.