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

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


当前回答

对于VS Code用户:

如果在尝试调试ASP . net Core应用程序时遇到此问题,请确保在tasks中定义构建任务。json,并且您可以在调试控制台窗格中看到其输出,则成功运行。

在启动中定义的调试配置。引用此任务的Json将出于某种原因(至少在某些情况下)继续执行定义的二进制文件,即使构建任务失败,并且由于构建任务失败,该二进制文件将成为最后一个成功构建的程序集。

其他回答

VS 2017的一些版本(结合。editorconfig)也有一个问题:从15.3开始,当文件的字符集与.editorconfig (utf8或utf8-bom)中的字符集不一致时,断点就不起作用了。

在我的案例中,问题在于ASP。在项目属性>>Web下未启用NET调试

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.

对我来说,那是在做一个网站项目的时候。在清理了这些临时文件夹后,我得到了正确的编译器错误:

C:\Documents and Settings\ %username%\AppData\Local\Temp\临时 ASP。网络文件 C: \ windows \ Microsoft.NET \ Framework \ v4.0.30319 \临时ASP。网 文件

我最终解决了这个问题,当我发现一个类文件,我故意移动到一个子文件夹,以某种方式重新出现在根文件夹。当我在编辑另一个的时候,VS用了那个。

你做过这种事吗?

是否继续运行最后一个成功的构建?

如果您勾选了方框并按下“是”,即使您的项目没有编译,您也将成功运行最后一个构建。这意味着无论何时设置断点,都将得到该错误。

试着改变这个值:

工具 选项 项目和解决方案 构建并运行 在运行时,发生构建或部署错误时:不启动