javascript - Stylesheets and scripts bundles not working in Mono - Stack Overflow

admin2025-04-19  0

Background: I am migrating an ASP.NET MVC 5 application (developed in Windows 8.1, VS2013 Community, .NET 4.5.1, MySql custom membership and role provider) project to Monodevelop (in Ubuntu 14.4, Monodevelop, Mono).

In my ~/App_Start/BundleConfig class

public static void RegisterBundles(BundleCollection bundles)
    {
        BundleTable.EnableOptimizations = true;

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

        bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                    "~/Scripts/modernizr-*"));
    }

In my ~/Views/Shared/_Layout.cshtml view

@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")

In my Web.Config

<add namespace="System.Web.Optimization" />

Also

<pilation defaultLanguage="C#" debug="false"> </pilation>

Also Microsoft.Web.Infrastructure.dll is deleted from the bin directory.

Problem: I don't see that the bundles are getting rendered when I view source in the browser:

The links are directing towards directories, It should show files in the directories

<link href="/Content/css" rel="stylesheet"/>
<script src="/bundles/modernizr"></script>

This bundling is working very fine on Windows but on Ubuntu, I see only directories

What am I doing wrong here?

Background: I am migrating an ASP.NET MVC 5 application (developed in Windows 8.1, VS2013 Community, .NET 4.5.1, MySql custom membership and role provider) project to Monodevelop (in Ubuntu 14.4, Monodevelop, Mono).

In my ~/App_Start/BundleConfig class

public static void RegisterBundles(BundleCollection bundles)
    {
        BundleTable.EnableOptimizations = true;

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

        bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                    "~/Scripts/modernizr-*"));
    }

In my ~/Views/Shared/_Layout.cshtml view

@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")

In my Web.Config

<add namespace="System.Web.Optimization" />

Also

<pilation defaultLanguage="C#" debug="false"> </pilation>

Also Microsoft.Web.Infrastructure.dll is deleted from the bin directory.

Problem: I don't see that the bundles are getting rendered when I view source in the browser:

The links are directing towards directories, It should show files in the directories

<link href="/Content/css" rel="stylesheet"/>
<script src="/bundles/modernizr"></script>

This bundling is working very fine on Windows but on Ubuntu, I see only directories

What am I doing wrong here?

Share Improve this question edited Jan 13, 2016 at 17:07 Mr.X asked May 28, 2015 at 6:15 Mr.XMr.X 31.4k27 gold badges147 silver badges229 bronze badges 6
  • 3 Are you debugging and have <pilation debug="true" /> or BundleTable.EnableOptimizations = false;? – rageit Commented Jun 17, 2015 at 11:14
  • @rageit - I am debugging and not able to see BundleTable.EnableOptimizations in my project. Is it something in web.config or BundleConfig? If yes how can I use it? – Mr.X Commented Jun 22, 2015 at 7:18
  • 1 Do you have a Microsoft.Web.Infrastructure.dll in your bin directory? If so, try deleting it. Mono has it's own implementation it will use if this file is missing. – Dave Alperovich Commented Jul 15, 2015 at 20:16
  • When optimization is turned off, is it including the individual files from the bundle? If not, then it's probably not finding the files for the bundle. If it does, then something is preventing the bundler from intercepting the route for the bundle's path when you have optimization turned on.. – Benjamin Anderson Commented Jul 22, 2015 at 15:52
  • @BenjaminAnderson - are you talking about Ubuntu or Windows? On Windows there is no issue. – Mr.X Commented Jul 22, 2015 at 15:55
 |  Show 1 more ment

2 Answers 2

Reset to default 6 +50

Inside your BundleConfig file add the following:

BundleTable.EnableOptimizations = true;

Then switch to release mode.

This should do the trick

I just came across this issue myself today. Mihai-Tibrea 's answer does indeed work, but it leads to unacceptable requirements for my purposes.

If always enabling bundling (BundleTable.EnableOptimizations = true; and/or build in release mode) is not acceptable consider the following:

In BundleConfig.cs find a line like this:

"~/Content/site.css"

Change that to

"~/Content/Site.css"

Note that in mono, the case of file names is very important, while that is not important in windows. So either your html needs to use lower-case site.css OR your bundle needs to start with a capital letter.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745003142a279352.html

最新回复(0)