krieg
krieg

Reputation: 257

BundleConfig.cs not referencing anything?

for starters, I ask all of you to bear with me since I'm really new to ASP and C# overall and I probably don't have most concepts as shaped as I'd want them to be.

I'm having some issues with BundleConfig.cs . Apparently every single module it attempts to reference doesn't work, or can't be found rather?

This is the BundleConfig I've got:

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

And this is what I'm referencing in my _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>

As it stands right now according to the developer tools provided by Google Chrome, it's not referencing anything at all:

No references?

I really don't know what to do. I've noticed that the bundle references certain things that my solution explorer does not show, for example there is no /css folder. I have been messing around with it for naught, haven't got any results or references.

In case you're curious, this is my solution explorer right now (I guess it shows the parts you might be interested in):

Solution Explorer

Do you have any idea why this could be happening?

Upvotes: 2

Views: 2221

Answers (1)

Russ Cam
Russ Cam

Reputation: 125538

You need to register the bundles with the application somewhere on application start using BundleConfig.RegisterBundles(BundleTable.Bundles); from the System.Web.Optimization assembly.

One place that this can be put is in the Application_Start() method in the global.asax file.

Bundle configuration is a way of configuring files to be combined and minified, by default to happen when the application is built with the release build configuration. So, the urls passed in the configuration don't point to files in the solution, but are endpoints that will serve up those files that are bundled and minified at runtime.

A good place to start is the bundling and minification article on the asp.net web site.

Upvotes: 5

Related Questions