在Visual Studio中调试时,有时我添加了一个断点,但它是空心的,VS说“断点目前不会被击中。”源代码与原始版本不同。”显然,这使我无法进行调试。
这条消息到底是什么意思?什么原始版本?如果我只是打开了解决方案,而没有对代码做任何更改,又怎么会有“原始版本”呢?
在Visual Studio中调试时,有时我添加了一个断点,但它是空心的,VS说“断点目前不会被击中。”源代码与原始版本不同。”显然,这使我无法进行调试。
这条消息到底是什么意思?什么原始版本?如果我只是打开了解决方案,而没有对代码做任何更改,又怎么会有“原始版本”呢?
当前回答
对我来说,解决方案隐藏在项目属性的高级构建设置中:
由于未知的原因,它被设置为none:将其设置为full会导致命中断点。
要进入此对话框,请打开项目属性,然后转到构建,然后选择高级…按钮在页面底部。
其他回答
从Visual Studio 2017 15.3.1到15.3.5,出现了解决此问题的新方法。如果您正在使用EditorConfig,则charset=utf8选项会导致这些症状。VS团队已经复制了这个,并表示他们正在努力。
因此,一个修复方法是注释掉.editorconfig文件中的charset=utf8行。
编辑:这应该在VS 15.5被修复。
This happen often also if you are using a file references to binaries (instead of project references to code in your project), and the compiled binary that you are referencing falls out of sync with the corresponding source code on your machine. This can happen because you downloaded a new version of the binary from source control without the new source code that went with it, or you have a few versions of the binary on your machine and are referencing an old copy, etc. If this is indeed the problem, it's a good reason to use project references as much as it practical.
正如它所说,“源代码与原始版本不同”。
右键单击解决方案资源管理器中的项目文件夹,并选择Clean。构建项目的新版本,断点将再次工作!
这也发生在调试一个c++项目时,该项目加载了一个用一些CLR语言(Managed c++, c#等)实现的模块。在这种情况下,错误消息确实具有误导性。
解决方案是将公共语言运行库(CLR)支持配置属性放入启动项目并重新编译它。
在某些情况下,重新编译和重新构建并不能帮助克服这个问题。 另一个潜在的解决方案是从解决方案资源管理器中删除带断点的源文件,然后重新添加它(例如通过从文件夹中拖放)。