ASP.Net MVC风格包不包括大多数文件 [英] ASP.Net MVC Style Bundle Not Including Most Files

查看:137
本文介绍了ASP.Net MVC风格包不包括大多数文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我的一个地方项目的副本完全失去了它的大部分造型。我花了一段时间来弄明白,因为大部分的造型在一个文件已完成,其余都像剑道和jQuery UI小事。

另外,次要的东西没有被添加到页面。我觉得这种服装已被其他开发人员修改(没有碰过这个项目在一段时间)谁是只测试Web API的东西,而不是UI,因此他可能已经破坏了它,从来不知道,但我找到了问题所在:只有的site.css 文件被包括在其他的束和none。我甚至尝试重新安排包含在包中的CSS文件的顺序,将只包含的site.css

我重建项目,清除缓存,等等,所以它肯定是看到变化。我记得更新一些的NuGet包或VS包或最近的东西 - 甚至可能是MVC包?

我的问题是:做了一些改变,使得这种情况发生?是什么造成的?

修改:从code BundleConfig.cs

 公共静态无效RegisterBundles(BundleCollection包)
{
    bundles.Add(新StyleBundle(〜/内容/ CSS)。包括(
            〜/内容/的site.css
            〜/内容/主题/剑道/ kendo.common.min.css
            〜/内容/主题/剑道/ kendo.default.min.css
            〜/内容/主题/基/缩小的/ jquery.ui.core.min.css
            〜/内容/主题/基/缩小的/ jquery.ui.resizable.min.css
            〜/内容/主题/基/缩小的/ jquery.ui.selectable.min.css
            〜/内容/主题/基/缩小的/ jquery.ui.accordion.min.css
            〜/内容/主题/基/缩小的/ jquery.ui.autocomplete.min.css
            〜/内容/主题/基/缩小的/ jquery.ui.button.min.css
            〜/内容/主题/基/缩小的/ jquery.ui.dialog.min.css
            〜/内容/主题/基/缩小的/ jquery.ui.slider.min.css
            〜/内容/主题/基/缩小的/ jquery.ui.tabs.min.css
            〜/内容/主题/基/缩小的/ jquery.ui.datepicker.min.css
            〜/内容/主题/基/缩小的/ jquery.ui.progressbar.min.css
            〜/内容/主题/基/缩小的/ jquery.ui.theme.min.css));
}

code _Layout.cshtml

  @ Styles.Render(〜/内容/主题/基/ CSS,〜/内容/ CSS)


解决方案

默认情况下,文件结尾的名字 .min.css 将只包含在发布生成。

推荐束配置是只包括非精缩.css和.js文件,那么.min版本会自动选择(如果存在)在发布版本,即<编译调试=假>以您的的Web.config

您可以通过清除,然后加无视规则的<一个控制此行为href=\"http://msdn.microsoft.com/en-us/library/system.web.optimization.bundlecollection.ignorelist.aspx\"><$c$c>BundleCollection.IgnoreList.一个例子 BundleConfig 可能看起来像这样:

 公共静态类BundleConfig
{
    公共静态无效RegisterBundles(BundleCollection包)
    {
        ConfigureIgnoreList(bundles.IgnoreList);        //设置你的包...
    }    公共静态无效ConfigureIgnoreList(IgnoreList ignoreList)
    {
        如果(ignoreList == NULL)抛出新的ArgumentNullException(ignoreList);        ignoreList.Clear(); //清除列表,然后添加新模式。        ignoreList.Ignore(* intellisense.js。);
        ignoreList.Ignore(* - vsdoc.js);
        ignoreList.Ignore(* debug.js,OptimizationMode.WhenEnabled);
        // ignoreList.Ignore(* min.js,OptimizationMode.WhenDisabled);
        ignoreList.Ignore(,OptimizationMode.WhenDisabled* min.css。);
    }
}

您也可以明确地启用/通过设置<一个禁用优化href=\"http://msdn.microsoft.com/en-us/library/system.web.optimization.bundletable.enableoptimizations.aspx\"><$c$c>BundleTable.EnableOptimizations.

Recently, my local copy of a project completely lost most of its styling. Took me a while to figure it out, as most of the styling was done in one file and the rest were minor things like Kendo and jQuery UI.

The other, minor stuff wasn't being added to the page. I thought the styles had been modified by another developer (haven't touched this project in a while) who was only testing the Web API stuff and not the UI so he could have wrecked it and never known, but I tracked down the problem: only the site.css file was being included in the bundle and none of the other ones. I even tried rearranging the order of the CSS files included in the bundle and it would ONLY include site.css.

I rebuilt the project, cleared the cache, etc., so it was definitely seeing changes. I remember updating some NuGet packages or VS packages or something lately - possibly even the MVC package?

My question is: Did something change that made this happen? What's causing this?

EDIT: Code from BundleConfig.cs:

public static void RegisterBundles(BundleCollection bundles)
{
    bundles.Add(new StyleBundle("~/Content/css").Include(
            "~/Content/site.css",
            "~/Content/themes/kendo/kendo.common.min.css",
            "~/Content/themes/kendo/kendo.default.min.css",
            "~/Content/themes/base/minified/jquery.ui.core.min.css",
            "~/Content/themes/base/minified/jquery.ui.resizable.min.css",
            "~/Content/themes/base/minified/jquery.ui.selectable.min.css",
            "~/Content/themes/base/minified/jquery.ui.accordion.min.css",
            "~/Content/themes/base/minified/jquery.ui.autocomplete.min.css",
            "~/Content/themes/base/minified/jquery.ui.button.min.css",
            "~/Content/themes/base/minified/jquery.ui.dialog.min.css",
            "~/Content/themes/base/minified/jquery.ui.slider.min.css",
            "~/Content/themes/base/minified/jquery.ui.tabs.min.css",
            "~/Content/themes/base/minified/jquery.ui.datepicker.min.css",
            "~/Content/themes/base/minified/jquery.ui.progressbar.min.css",
            "~/Content/themes/base/minified/jquery.ui.theme.min.css"));
}

Code from _Layout.cshtml:

@Styles.Render("~/Content/themes/base/css", "~/Content/css")

解决方案

By default, files with names ending in ".min.css" will only be included in release builds.

The recommended bundle configuration is to only include non-minified .css and .js files, then the .min version will be automatically selected (if it exists) in release builds, i.e. <compilation debug="false">in your Web.config.

You can control this behavior by clearing and then adding ignore rules to the BundleCollection.IgnoreList. An example BundleConfig could look like this:

public static class BundleConfig
{
    public static void RegisterBundles(BundleCollection bundles)
    {
        ConfigureIgnoreList(bundles.IgnoreList);

        // Setup your bundles...
    }

    public static void ConfigureIgnoreList(IgnoreList ignoreList)
    {
        if (ignoreList == null) throw new ArgumentNullException("ignoreList");

        ignoreList.Clear(); // Clear the list, then add the new patterns.

        ignoreList.Ignore("*.intellisense.js");
        ignoreList.Ignore("*-vsdoc.js");
        ignoreList.Ignore("*.debug.js", OptimizationMode.WhenEnabled);
        // ignoreList.Ignore("*.min.js", OptimizationMode.WhenDisabled);
        ignoreList.Ignore("*.min.css", OptimizationMode.WhenDisabled);
    }
}

You can also explicitly enable/disable the optimization by setting BundleTable.EnableOptimizations.

这篇关于ASP.Net MVC风格包不包括大多数文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆