简体   繁体   中英

Visual Studio Code .Net Core debugging error 'source code is different from original'

(I refer Visual Studio Code as vscode)

I am working on Asp.Net Mvc project with.Net Core 2.2. If I do not modify the source code after I open vscode, I can debug/run the project within vscode without any problem. But after I modify the source code, if I debug, vscode gives me warning

Breakpoint warning: The source code is different from the original version. To allow this breakpoint to be hit: Add '"requireExactSource": false' to launch.json and restart debugging.

when i put a breakpoint and it comes disabled automatically. Also i can not see the last changes in the running project.

To be able to see the last modifications, I have to debug with Visual Studio once, and then if I debug/run the source code with vscode again, no problem till I modify the source code again.

How can I fix this situation?

Note: There is a similar question here but it says s/he can not use breakpoints since first run and the problem is related to dotnet path. My problem is completely different.

TL;DR check if vscode is building the right project/solution. dotnet build the main/entrance/single project does not build other dependency projects.

The root of the problem comes from tasks.json for me. The target for the build task was set wrong. It only builds a single project of a whole solution while the work is done on other projects of the solution.

My fix was modifying the building task to build the whole solution instead of a single project.

Debugging with Visual Studio was fixing the problem temporarly because it was building the whole solution which reflects the last modifications.

This SO answer is also related to this question.

Sample launch.json and tasks.json for.Net core .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM