Bundling not working in MVC5 when I turn on release mode

后端 未结 7 1644
耶瑟儿~
耶瑟儿~ 2020-12-15 03:46

I have the following bundle configured in BundleConfig.cs:

bundles.Add(new StyleBundle(\"~/bundles/css\").Include(
                      \"~/assets/bootstrap         


        
相关标签:
7条回答
  • 2020-12-15 04:24

    After fighting against this issue for several hours, I recommend that you try this as well:

    1. Add this at the very beginning of the view you are using your bundle:

      @{ BundleTable.EnableOptimizations = true; }

    2. Reset IIS

    3. Reload your page and check if minify works

    In my case somewhere in my solution was changing "BundleTable.EnableOptimizations" from true to false. When I force that to TRUE right before the bundle is used, I got this working.

    After I noticed it works, I moved that into a static method at my BundleConfig class:

    public static void EnableOptimizations()
    {
        #if DEBUG
            BundleTable.EnableOptimizations = false;
        #else
            BundleTable.EnableOptimizations = true;
        #endif
    }
    

    So I can call it from the view and have it minify disabled for developers

    @{
        BundleConfig.EnableOptimizations();
    }
    
    0 讨论(0)
提交回复
热议问题