herzbube
herzbube

Reputation: 13378

Visual Studio 2017 claims I am debugging a release build of my C++/CLI project

After updating from Visual Studio 2013 to Visual Studio 2017, if I try to start a debug session of my C++/CLI project (.vcxproj project file) Visual Studio stops and displays a dialog which says:

You are debugging a Release build of Foo.exe. Using Just My Code with Release builds using compiler optimizations results in a degraded debugging experience (e.g. breakpoints will not be hit).

I can then either stop debugging or continue with the debug session, either with "Just My Code" turned on or off.

The project is clearly built with Debug information and without any optimization whatsoever. Consequently, the old Visual Studio 2013 did not show any warning.

Both this SO question and this SO question deal with the same warning emitted by Visual Studio 2015, but after reading through the suggestions and hints offered there I have to say that none of them seems a convincing solution to my problem. Specifically, I was able to get rid of the warning by enabling the Visual Studio option "Suppress JIT optimization on module load (Managed only)", but I think this is only treating a symptom, not fixing the actual cause of the problem.

What do I have to do to make Visual Studio 2017 detect that my C++/CLI project is a debug build so that it no longer displays the annoying (and actually misleading) warning?

Environment:

Upvotes: 3

Views: 2603

Answers (1)

herzbube
herzbube

Reputation: 13378

The solution to my problem is that the project needs to be built with the project setting "Debuggable Assembly" set to "Yes" (linker option /ASSEMBLYDEBUG). By default this linker option is unset and apparently defaults to /ASSEMBLYDEBUG:DISABLE. Cf. Microsoft's documentation of the linker option.

Setting /ASSEMBLYDEBUG is the same as writing

[assembly:Debuggable(true, true)];

in code. According to the MSDN documentation of this DebuggableAttribute constructor, this code tells the debugger to set

  • isJITTrackingEnabled = true
  • isJITOptimizerDisabled = true

So the initial workaround I mentioned in the question, where I enabled the Visual Studio option "Suppress JIT optimization on module load (Managed only)", wasn't too far off the track. But I believe that knowing what I'm doing and setting a fine-grained, project-specific linker setting is preferrable to having no clue and randomly making a change to a global Visual Studio setting.

Upvotes: 1

Related Questions