MVC条件编译符号调试 - 发布

时间:2011-09-08 22:48:24

标签: asp.net-mvc-3

据我所知,在Project-> Properties-> Build设置下有一个'Define DEBUG constant'。默认情况下,“Debug”配置选中此选项,这意味着'#if DEBUG'应该评估尝试。此外,默认情况下,“Release”配置不会选中此选项。

我在MVC 3应用程序中使用vs2010 sp1进行编程,以下是我所做的:

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

我的问题是无论构建类型,Release还是Debug,我都会收到“Debug Build”的警告。

我做错了什么?

2 个答案:

答案 0 :(得分:2)

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

会起作用,但不会像#DEBUG那样进行优化,即使在VS外被淹没也会被击中

答案 1 :(得分:1)

不幸的是,这永远不会奏效。您需要在控制器中设置的视图包中放置一些东西。

相关问题