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

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


当前回答

工具 选项 调试 一般

取消选中“要求源文件与原始版本完全匹配”

其他回答

这也发生在调试一个c++项目时,该项目加载了一个用一些CLR语言(Managed c++, c#等)实现的模块。在这种情况下,错误消息确实具有误导性。

解决方案是将公共语言运行库(CLR)支持配置属性放入启动项目并重新编译它。

我遇到了这个问题,这是因为我们的DevOps团队要求Azure云设置。在开发时,只需将其从Web.config中删除。

<httpRuntime maxRequestLength="102400" />

    <!--TODO #5 comment out for IIS Express fcnMode goes with httpRunTime above in other environment just in DEV -->
    <!--fcnMode="Disabled"/>-->

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.

我在将一个项目从netcoreapp2.0升级到netcoreapp2.2后遇到了这个问题。

我只是通过编辑.csproj文件中的TargetFramework条目来做到这一点,而忽略了对launch.json进行更改。

"program": "${workspaceFolder}/src/MyProject/bin/Debug/netcoreapp2.0/MyProject.dll"

这意味着VS Code总是加载旧的2.0版本的项目。我在删除/bin和/obj中的所有内容后才发现它,然后它根本不会运行,直到我在上面的路径中发现2.0。

尽管所有的答案,我的问题实际上不同于这里提到的!

确保您的属性->构建选项卡->输出路径指向与您所选择的构建配置的解决方案中所有其他项目相同的位置!

如果你的启动项目将它的可执行文件从你试图调试的dll发送到不同的文件夹,你可能会遇到问题,尽管你的构建和visual studio工作完美。