12

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

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

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?

Zameer Ansari
  • 28,977
  • 24
  • 140
  • 219
  • 3
    Are you debugging and have `` or `BundleTable.EnableOptimizations = false;`? – rageit Jun 17 '15 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? – Zameer Ansari Jun 22 '15 at 07: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 Jul 15 '15 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 Jul 22 '15 at 15:52
  • @BenjaminAnderson - are you talking about Ubuntu or Windows? On Windows there is no issue. – Zameer Ansari Jul 22 '15 at 15:55
  • Are you sure you meant `MVC 5`? `MVC 5` doesn't use bundler, opting for `gulp` or `grunt` task runners instead. – OneHoopyFrood Jul 22 '15 at 17:26

2 Answers2

6

Inside your BundleConfig file add the following:

BundleTable.EnableOptimizations = true;

Then switch to release mode.

This should do the trick

Amirhossein Mehrvarzi
  • 18,024
  • 7
  • 45
  • 70
Mihai Tibrea
  • 641
  • 5
  • 23
1

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.

D. Squire
  • 1,501
  • 1
  • 8
  • 10