BundleConfig.cs没有引用任何东西?

时间:2014-09-26 02:02:26

标签: c# asp.net asp.net-mvc razor bundling-and-minification

对于初学者来说,我要求你们所有人都要忍受我,因为我对ASP和C#总体上并不熟悉,而且我可能没有像我想要的那样塑造大多数概念。是

我在使用BundleConfig.cs时遇到了一些问题。显然,它试图引用的每个模块都不起作用,或者找不到它?

这是我所拥有的BundleConfig:

using System.Web;
using System.Web.Optimization;

namespace WebApplication
{
    public class BundleConfig
    {
        // For more information on Bundling, visit http://go.microsoft.com/fwlink/?LinkId=254725
        public static void RegisterBundles(BundleCollection bundles)
        {
            bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                        "~/Scripts/jquery-{version}.js"));

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

            bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                        "~/Scripts/jquery.validate*"));

            // 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 StyleBundle("~/Content/css").Include("~/Content/site.css"));

            bundles.Add(new StyleBundle("~/Content/themes/base/css").Include(
                        "~/Content/themes/base/jquery.ui.core.css",
                        "~/Content/themes/base/jquery.ui.resizable.css",
                        "~/Content/themes/base/jquery.ui.selectable.css",
                        "~/Content/themes/base/jquery.ui.accordion.css",
                        "~/Content/themes/base/jquery.ui.autocomplete.css",
                        "~/Content/themes/base/jquery.ui.button.css",
                        "~/Content/themes/base/jquery.ui.dialog.css",
                        "~/Content/themes/base/jquery.ui.slider.css",
                        "~/Content/themes/base/jquery.ui.tabs.css",
                        "~/Content/themes/base/jquery.ui.datepicker.css",
                        "~/Content/themes/base/jquery.ui.progressbar.css",
                        "~/Content/themes/base/jquery.ui.theme.css"));
        }
    }
}

这就是我在_Layouyt.cshtml中引用的内容

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width" />
        <title>@ViewBag.Title</title>
        @Styles.Render("~/Content/css")
        @Styles.Render("~/Content/themes/base/css")
        @Styles.Render("~/Content/site.css")
        @Scripts.Render("~/bundles/modernizr")
        @Scripts.Render("~/bundles/jquery")
        @Scripts.Render("~/bundles/jqueryui")
        @Scripts.Render("~/Scripts/jquery.validate.min.js")
        @Styles.Render("~/Content/bootstrap.min.css")
        @Styles.Render("~/Content/layoutsheet.css")
    </head>
    <body>
    ....
    </body>
</html>

根据谷歌浏览器提供的开发者工具,它现在就是现在,它根本没有引用任何内容:

No references?

我真的不知道该怎么做。我注意到捆绑包引用了我的解决方案资源管理器未显示的某些内容,例如没有/ css文件夹。我一直在乱搞它,没有任何结果或参考。

如果你有点好奇,这就是我现在的解决方案资源管理器(我想它会显示你可能感兴趣的部分):

Solution Explorer

你知道为什么会发生这种情况吗?

1 个答案:

答案 0 :(得分:5)

您需要在应用程序启动时使用BundleConfig.RegisterBundles(BundleTable.Bundles);程序集中的System.Web.Optimization向应用程序注册捆绑包。

可以放置的一个地方是Application_Start()文件中的global.asax方法。

捆绑配置是一种配置要合并和缩小的文件的方法,默认情况下在使用发布版本配置构建应用程序时会发生。因此,配置中传递的URL不会指向解决方案中的文件,而是提供在运行时捆绑和缩小的文件的端点。

一个好的起点是asp.net网站上的bundling and minification article