Visual Studio 2017 声称我正在调试我的 C++/CLI 项目的发布版本

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

从 Visual Studio 2013 更新到 Visual Studio 2017 后,如果我尝试启动我的 C++/CLI 项目(.vcxproj 项目文件)的调试会话,Visual Studio 会停止并显示一个对话框说:

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

然后我可以停止调试或继续调试会话,打开或关闭 "Just My Code"。

该项目显然是使用调试信息构建的,没有任何优化。因此,旧的 Visual Studio 2013 没有显示任何警告。

and 都处理了 Visual Studio 2015 发出的相同警告,但在阅读了那里提供的建议和提示后,我不得不说其中 none 似乎令人信服解决我的问题。具体来说,我 能够通过启用 Visual Studio 选项 "Suppress JIT optimization on module load (Managed only)" 来消除警告,但我认为这只是治标不治本,并没有解决实际问题问题的原因。

我需要做什么才能使 Visual Studio 2017 检测到我的 C++/CLI 项目是调试版本,以便它不再显示烦人的(实际上是误导性的)警告?

环境:

我的问题的解决方案是需要将项目设置 "Debuggable Assembly" 设置为 "Yes"(链接器选项 /ASSEMBLYDEBUG)来构建项目。默认情况下,此链接器选项未设置,显然默认为 /ASSEMBLYDEBUG:DISABLE。比照。微软的 documentation of the linker option.

设置/ASSEMBLYDEBUG等同于写

[assembly:Debuggable(true, true)];

在代码中。根据此 DebuggableAttribute 构造函数的 MSDN documentation,此代码告诉调试器设置

  • isJITTrackingEnabled = true
  • isJITOptimizerDisabled = true

所以我在问题中提到的初始解决方法,我启用了 Visual Studio 选项 "Suppress JIT optimization on module load (Managed only)",并没有偏离轨道太远。但我相信知道我在做什么并设置一个细粒度的、特定于项目的链接器设置比没有任何线索并随机更改全局 Visual Studio 设置更可取。