Stephen Cossgrove
Stephen Cossgrove

Reputation: 11

MVC Condition Compilation Symbols Debug - Release

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?

Upvotes: 1

Views: 896

Answers (2)

Davi Fiamenghi
Davi Fiamenghi

Reputation: 1265

@{
    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

Upvotes: 2

kmcc049
kmcc049

Reputation: 2801

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

Upvotes: 1

Related Questions