Bundling with MVC4 not working after I publish to azure

前端 未结 9 2177
闹比i
闹比i 2021-02-08 14:52

Hi I am trying to bundle my scripts for my application. My debug is working and if I publish with the Web.debug every thing works fine. But when I publish with the Web.releas my

相关标签:
9条回答
  • 2021-02-08 15:35

    In my case of missing stylesheets, the problem was not due to the vagaries of publication to Azure, failures during minification or conflicting virtual and real paths.

    It was due to the different behaviours of BundleCollection.Add(Bundle) between Debug and Release.

    If you manage to do the following (for example, because you're using Durandal from NuGet and have multiple BundleConfig's initialized by WebActivator, and you didn't really write any of them yourself)

    bundles.Add(new StyleBundle("/foo").Include("/a.css")); 
    bundles.Add(new StyleBundle("/foo").Include("/b.css"));
    

    Basically, if the bundles don't minify, this works: you get elements in your Razor page for both /foo/a.css and /foo/b.css.

    But if minification is engaged, then b.css doesn't make it into the resulting minified resource. (or is a.css replaced ... I wasn't paying attention ... just trying to get it to work).

    You can work around this by understanding the order of loading and using:

    bundles.Add(new StyleBundle("/foo").Include("/a.css")); 
    bundles.Add(bundles.GetBundleFor("/foo").Include("/b.css"));
    

    ... or by using a different named path (if that's really your intention), or refining your strategy to bundling initialization (which may potentially break NuGet updates).

    If only the stupid 'documentation' for System.Web.Optimization classes actually bothered to specify the behaviour of adding multiple bundles with the same virtual path, we need not be having this discussion.

    0 讨论(0)
  • 2021-02-08 15:36

    I had a similar problem when publishing to Azure. The error was actually telling me that the jQuery file was bad formatted. ==> minified file that is.

    The other scripts failed because jQuery was not identified.

    I was using jQuery 2.0.0 (from NuGet). After upgrading today to 2.0.2 (from NuGet) I was able to publish successful to Azure under Release configuration.

    Not sure if this is linked to your specific problem, but it solved mine.

    0 讨论(0)
  • 2021-02-08 15:39

    really simple fix for this one:

    I had the following:

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

    i also had a folder in my solution at:

    /Content/Css
    

    That was the problem, the stylebundle had the same name as a folder in my solution.

    Renamed the stylebundle to:

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

    and (remember) to change where you referrence it, _Layout.cshmtl

    So to make this clear, if your stylebundle name is the same as an actual folder in your solution then you're gonna get this issue. Simply name it something different.

    0 讨论(0)
提交回复
热议问题