Search code examples
c#asp.net-mvcbundling-and-minification

Disable EnableOptimizations on Debug mode


Can you tell me how to handle 'BundleConfig.cs' file's below line when we are working on debug mode ? Because I need to ignore below line on debug mode.How can I do that ? Any help would be highly appreciated.

BundleTable.EnableOptimizations = true;

Solution

  • The easiest way is to use the #if Preprocessor directive

    #if DEBUG
        BundleTable.EnableOptimizations = false;
    #else
        BundleTable.EnableOptimizations = true;
    #endif
    

    If your app is running in debug mode, Visual Studio defines DEBUG for you. On the other hand, if your app is running in release, DEBUG will be undefined.

    In order to check if it's a release version, you check for DEBUG to not be defined

     #if !DEBUG
         BundleTable.EnableOptimizations = true;
     #endif
    

    PS: For obvious reasons, there is no RELEASE flag.