views:

66

answers:

6

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 appear in the release version of a component I wrote. I suspect that I might have mess up my csproject setting.

Any idea why Debug.Assert appears in release mode?

P/S: I have double checked to make sure that I was really compiling in release mode before asking this question.

Note 2: I've double checked my csproject, and I found that in the Release config, the Define DEBUG constant is not ticked, indicating that for this part my setting is correct.

A: 

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.

Russ C
+3  A: 

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.

madgnome
I double-checked; in `release` config the **DEBUG** constant is not there.
Ngu Soon Hui
+1 for `#define DEBUG` which appears to be the cause...
Pontus Gagge
+2  A: 

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>
rdkleine
A: 

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

Ngu Soon Hui
That'll ruin your day ;)
rdkleine
A: 

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?

Rob Levine
A: 

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 possibiliy 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.

Dan Puzey