1

It is my understanding that under the Project->Properties->Build settings there is a 'Define DEBUG constant'. By default the "Debug" configuration has this option checked, which means that '#if DEBUG' should evaluate to try. Also by default the "Release" configuration has this option not checked.

I am programming under vs2010 sp1 in a MVC 3 application and the following is what i have done:

@{ 
#if DEBUG
    <script language="javascript" type="text/javascript">
        $(document).ready(function () {
            // put all your jQuery goodness in here.
            alert('Debug Build');
        });
    </script>
#else    
    <script language="javascript" type="text/javascript">
        $(document).ready(function () {
            // put all your jQuery goodness in here.
            alert('Release Build');
        });
    </script>
#endif }

My problem is that regardless of the build type, Release or Debug, i am getting the alert for 'Debug Build'.

What am i doing wrong?

2 Answers2

2
@{
    if(System.Diagnostics.Debugger.IsAttached)
    {
        <script type="text/javascript">
        </script>      
    }
}

Will work, but isn't optimized like #DEBUG and will be hit even if being debuged outside VS

Davi Fiamenghi
  • 1,237
  • 12
  • 28
  • Aren't you talking about two different things, i.e. if the compilation has been done with debug symbols vs. if a debugger is attached? – Ted Nyberg Nov 10 '12 at 10:23
1

That will never work unfortunately. You will need to put something in the viewbag that you set from your controller.

kmcc049
  • 2,783
  • 17
  • 13