C# 使用bootstrap.min.css的BundleConfig.cs

C# 使用bootstrap.min.css的BundleConfig.cs,c#,css,asp.net-mvc,twitter-bootstrap,C#,Css,Asp.net Mvc,Twitter Bootstrap,我的BundleConfig.cs文件如下所示(CSS): 不,我在哪里调用bootstrap.min.css,但是,当我只更新bootstrap.css文件时,我的任何更改都无法识别。我开始在.min文件中进行更改,然后我注意到了我的更改 我得到BundleTable.EnableOptimizations=true获取所有的.css文件并将其最小化,但我不明白为什么我必须更新.min文件才能识别我的样式更改 我希望bootstrap.css文件在内存中最小化并以这种方式使用 有人能解释为什么

我的
BundleConfig.cs
文件如下所示(CSS):

不,我在哪里调用bootstrap.min.css,但是,当我只更新bootstrap.css文件时,我的任何更改都无法识别。我开始在.min文件中进行更改,然后我注意到了我的更改

我得到
BundleTable.EnableOptimizations=true
获取所有的.css文件并将其最小化,但我不明白为什么我必须更新.min文件才能识别我的样式更改

我希望
bootstrap.css
文件在内存中最小化并以这种方式使用

有人能解释为什么会发生这种情况吗


为了获得更多信息,我在VS2013中使用MVC5

当您在捆绑包中包含
样式表.css
并且您的项目中已经有
样式表.min.css
文件时,当
BundleTable.EnableOptimizations==true
时,优化框架将使用
.min
文件

它对
script.min.js
文件执行相同的操作

BundleTable.EnableOptimizations = true; // when this is not false
bundles.Add(new StyleBundle("~/Content/css").Include(
    "~/Content/bootstrap.css", // will look for bootstrap.min.css
    "~/Content/site.css", // will look for site.min.css
    "~/Content/bootstrap-switch.css", // will look for bootstrap-switch.min.css
    "~/Content/datepicker.css", // will look for datepicker.min.css
    "~/Content/bootstrap-duallistbox.css", // will look for bootstrap-duallistbox.min.css
    "~/Content/fullcalender.css", // will look for fullcalender.min.css
    "~/Content/fullcalender.print.css")); // will look for fullcalender.print.min.css
如果您希望优化框架缩小,只需从项目中删除bootstrap.min.css即可

:

前面的代码创建了一个名为~/bundles/jquery的新JavaScript包,其中包括脚本文件夹中与通配符字符串“~/Scripts/jquery-{version}.js”匹配的所有适当(即调试或缩小但不是.vsdoc)文件。对于ASP.NET MVC 4,这意味着通过调试配置,jquery-1.7.1.js文件将添加到包中。在发布配置中,将添加jquery-1.7.1.min.js。捆绑框架遵循以下几种常见约定:

  • 当“FileX.min.js”和“FileX.js”存在时,选择要发布的“.min”文件
  • 选择非“.min”版本进行调试
  • 忽略仅由IntelliSense使用的“-vsdoc”文件(如jquery-1.7.1-vsdoc.js)

您没有在发布模式下运行,是吗?@Michel OP有
BundleTable.EnableOptimizations=true设置,模拟在发布模式下发生的事情。谢谢。这似乎是一个合乎逻辑的答案。有任何文档支持这一点吗?@webdad3我已经更新了我的答案,其中引用了asp.net网站上的文档。注意,样式包与脚本包同样适用。需要明确的是,绑定程序不使用min版本来避免工作。它实际上是一个安全警卫。缩小并不是一门完美的科学,根据源代码的复杂性,某些缩小协议可能会包含文件的内容,导致文件不再正常工作。通过包含
.min
版本,您指示捆绑程序使用首选的精简源代码,而不是创建自己的源代码。它仍然会将此与其他一切捆绑在一起;它只是将其排除在缩小周期之外。
BundleTable.EnableOptimizations = true; // when this is not false
bundles.Add(new StyleBundle("~/Content/css").Include(
    "~/Content/bootstrap.css", // will look for bootstrap.min.css
    "~/Content/site.css", // will look for site.min.css
    "~/Content/bootstrap-switch.css", // will look for bootstrap-switch.min.css
    "~/Content/datepicker.css", // will look for datepicker.min.css
    "~/Content/bootstrap-duallistbox.css", // will look for bootstrap-duallistbox.min.css
    "~/Content/fullcalender.css", // will look for fullcalender.min.css
    "~/Content/fullcalender.print.css")); // will look for fullcalender.print.min.css
public static void RegisterBundles(BundleCollection bundles)
{
     bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                 "~/Scripts/jquery-{version}.js"));
         // Code removed for clarity.
}