在Visual Studio中调试时,有时我添加了一个断点,但它是空心的,VS说“断点目前不会被击中。”源代码与原始版本不同。”显然,这使我无法进行调试。

这条消息到底是什么意思?什么原始版本?如果我只是打开了解决方案,而没有对代码做任何更改,又怎么会有“原始版本”呢?


当前回答

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.

其他回答

我在VSCode中遇到了这个问题,问题是我在编辑器中看到的文件与项目正在构建的文件的副本不相同。我将一个c#库的存储库克隆到两个位置,一个在编辑器中打开,另一个由项目链接。如果清洁建筑不适合你,请检查你在编辑器中查看的文件副本是否正确!

有时您只需要将解决方案配置从“发布”更改为“调试”。

我已经试过提出的解决办法了,但不管用。

如果您有多个项目,请将要调试的项目作为启动项目。

对我来说,解决方案隐藏在项目属性的高级构建设置中:

由于未知的原因,它被设置为none:将其设置为full会导致命中断点。

要进入此对话框,请打开项目属性,然后转到构建,然后选择高级…按钮在页面底部。

对于一个类似的问题,我做了如下处理:

取消选中Debug -> option -> General菜单中的“Enable Just My Code”选项