Debug.Assert Appears in Release Mode

后端 未结 6 1901
北海茫月
北海茫月 2021-01-07 21:40

We all know that Debug.Assert will not be compiled into the dlls when compiled in release mode. But for some reason Debug.Assert did appea

相关标签:
6条回答
  • 2021-01-07 21:57

    Remember that "Release mode" is just a build configuration with a name of "Release". That doesn't necessarily imply anything about the compilation settings being used: it's perfectly possible to create a configuration called "Release" that actually compiles everything with debug settings. Or, in fact, doesn't compile anything at all!

    The other answers suggest a few of the places to look - but basically it sounds like either your project or solution settings have reconfigured "Release" builds to include debug information.

    On possibility not mentioned yet: in VS, if you drop down the build configuration combobox (where you normally select "Debug" or "Release") and select "Configuration Manager," you can see what each solution build configuration means for each of your projects. You'll note that you can, for example, configure a "Release" build on the solution to still build some components in Debug mode if you wanted to.

    0 讨论(0)
  • 2021-01-07 22:04

    I found out the answer; it's because there is a #define DEBUG preprocessor defined at the start of a cs file inside the project. Removing it solves the problem

    0 讨论(0)
  • 2021-01-07 22:04

    Do you use any kind of build process, such as Nant or MSBuild, or even a web-deployment project?

    Also, make sure that in release mode, go to your project properties and check the 'Define DEBUG Constant' isn't checked.

    0 讨论(0)
  • 2021-01-07 22:13

    Check the DefineConstants property in your project file, it should be :

    • <DefineConstants>DEBUG;TRACE</DefineConstants> for Debug configuration
    • <DefineConstants>TRACE</DefineConstants> for Release configuration

    Check that you haven't any #define DEBUG in your code.

    0 讨论(0)
  • 2021-01-07 22:14

    Have you checked the Project File? Define constants should NOT contain DEBUG

    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
        <DebugType>pdbonly</DebugType>
        <Optimize>true</Optimize>
        <OutputPath>bin\Release\</OutputPath>
        <DefineConstants>TRACE</DefineConstants>
        <ErrorReport>prompt</ErrorReport>
        <WarningLevel>4</WarningLevel>
      </PropertyGroup>
    
    0 讨论(0)
  • 2021-01-07 22:16

    As a further to the point that madgnome and rdkleine have made, can you also check that when the solution is set to build in release mode, that your project is also set to build in release mode. It is possible to have a project build in debug mode, when release is set at the project level.

    For this, right click in VS solution explorer on the solution and select Configuration Manager. Check that for "Active solution Configuration" of release you project says release, not debug, for its configuration.

    If this still sheds no light, then can you add a piece of code surrounded by an "#if DEBUG" and see if this gets compiled in?

    0 讨论(0)
提交回复
热议问题