3

In my view like that in debug mode to view Site.css use her, and when compiled in release mode the view using CSS-min.css site.

Something like this:

# if (Debug)
             / / CSS
# elif (Release)
             / / CSS Min-
# endif

But in my view .cshtml

ridermansb
  • 10,779
  • 24
  • 115
  • 226

2 Answers2

3

You can use Context.IsDebuggingEnabled. This boolean property is controlled by the debug attribute from the compilation section in web.config.

Here's a sample for your view.cshtml :

if (Context.IsDebuggingEnabled)
{
    // use something.css
}
else
{
    // use something.min.css
}
Alexandre Jobin
  • 2,811
  • 4
  • 33
  • 43
  • Does not work! I compile in release mode and `Context.IsDebuggingEnabled` property = true PS: in my Web.Release.config – ridermansb Sep 23 '11 at 01:12
  • 1
    Its because the compilation inside Visual Studio never use the transform feature. He always use web.config wherever you are in Debug or Release mode. The transformation occur when you publish your website. For a quick test, just change the debug attribute inside web.config. – Alexandre Jobin Sep 23 '11 at 12:42
  • It worked! If you change manually works. Well, it helps me, but it's strange, I would like to work whenever you select how to build in toolbar – ridermansb Sep 23 '11 at 14:08
  • you are right that it is strange that visual studio doesnt transform the .config files on build. It would be great to have this feature in the next Visual Studio version since that its just a normal behaviour of the build process to use the right config file depending of the build mode! – Alexandre Jobin Sep 23 '11 at 14:39
  • It's not strange. If you want Web.config file is transformed on build so where is it after build successfully? You don't want original Web.config file is overwritten. – Tien Do Feb 14 '12 at 16:26
0

asp.net mvc - Razor view engine, how to enter preprocessor(#if debug) - Stack Overflow

How about this?

Community
  • 1
  • 1
takepara
  • 10,413
  • 3
  • 34
  • 31