0

I want something like the below, if my application is being build under release mode, then my min js file needs to be referred in the view(.cshtml) but if the same application has been rendered in the debug mode, then the raw js file needs to be called. Can you suggest the piece of code which i need to write in my view(.cshtml)?

user5075511
  • 421
  • 1
  • 5
  • 11
  • Look through the answer to the question here: http://stackoverflow.com/questions/22489741/bundle-config-confused-about-debug-and-release-and-minification – Omar Himada Aug 27 '15 at 20:59
  • You don't need any code in your view. This is all handles by the [bundling and minification](http://www.asp.net/mvc/overview/performance/bundling-and-minification) features of MVC –  Aug 27 '15 at 22:19

2 Answers2

1

Create html helper

public static bool IsReleaseBuild(this HtmlHelper helper)
{
#if DEBUG
    return false;
#else
    return true;
#endif
}

in view do

@{#if (DEBUG) 
       <script type="text/javascript" src="file1.js"></script>

#else 
    <script type="text/javascript" src="file1.min.js"></script>
#endif
}
Janusz Nowak
  • 2,595
  • 1
  • 17
  • 36
0

I have referred the below Razor view engine, how to enter preprocessor(#if debug)

  public static bool IsDebug(this HtmlHelper htmlHelper)
    {
#if DEBUG
      return true;
#else
      return false;
#endif
    }
Then used it in my views like so:

            <section id="sidebar">
              @Html.Partial("_Connect")
@if (!Html.IsDebug())
{ 
              @Html.Partial("_Ads")
}
              <hr />
              @RenderSection("Sidebar", required: false)
            </section>
user5075511
  • 421
  • 1
  • 5
  • 11