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

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


当前回答

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

其他回答

在某些情况下,重新编译和重新构建并不能帮助克服这个问题。 另一个潜在的解决方案是从解决方案资源管理器中删除带断点的源文件,然后重新添加它(例如通过从文件夹中拖放)。

确保在csproj中将<Optimize>false</Optimize>设置为false

对我来说;我的网站在默认网站(http://localhost/myapp/)下的IIS应用程序中运行,并且IIS应用程序的映射指向的磁盘路径与我正在处理的源代码不同。

解决;重新映射您的IIS应用程序到与您正在构建的源代码相同的路径。

(如果您在磁盘的不同位置运行同一个应用程序的多个版本,就会发生这种情况)

如果您在调试构建配置中未选中DLL项目,那么您的新代码将永远无法构建!

转到构建—>配置管理器…(在VS2010中),并检查您正在尝试调试的代码的项目是否为当前构建配置进行了检查。

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.