简体   繁体   English

Visual Studio javascript 调试不起作用

[英]Visual Studio javascript debugging not working

This blog: Debug JavaScript in Microsoft Edge from Visual Studio https://devblogs.microsoft.com/visualstudio/debug-javascript-in-microsoft-edge-from-visual-studio/ describes how VS is supposed to debug javascript.这篇博客:Debug JavaScript in Microsoft Edge from Visual Studio https://devblogs.microsoft.com/visualstudio/debug-javascript-in-microsoft-edge-from-visual-studio/描述了 VS 应该如何调试 EF2919ZDE9BFFEE780E27

It looks great.看起来不错。 However, I cannot get it to work.但是,我无法让它工作。 I have a.Net Core 3.1 Razor project.我有一个.Net Core 3.1 Razor 项目。

In IE, Edge, Edge Beta, and Chrome I cannot get the script debugger to work.在 IE、Edge、Edge Beta 和 Chrome 中,我无法让脚本调试器工作。 I have uninstalled all my Visual Studio versions.我已经卸载了我所有的 Visual Studio 版本。 I have re-installed VS 2019 Community, 16.5.4我已经重新安装了 VS 2019 Community, 16.5.4

My breakpoints always look like this:我的断点总是这样:

在此处输入图像描述

Visual Studio javascript debugging not working Visual Studio javascript 调试不起作用

I am afraid that you cannot get what you want in cshtml file .恐怕你无法在 cshtml 文件中得到你想要的东西 As this similar issue said, you cannot debug js code in cshtml file and only for code in separate xxx.js (or xxx.ts ) files.正如这个类似的问题所说,您不能调试 cshtml 文件中的 js 代码,只能调试单独的xxx.js (或xxx.ts )文件中的代码。

Solution解决方案

Instead , you should create a new js file and then migrate these js code into this file and then it should work.相反,您应该创建一个新的 js 文件,然后将这些 js 代码迁移到该文件中,然后它应该可以工作。

And when you debug your project and load this cshtml page, the breakpoint will not appear and when you finish loading the page, then the breakpoint will appear.当你调试你的项目并加载这个cshtml页面时,断点不会出现,当你完成页面加载时,断点就会出现。 And this is the cshtml feature.这就是 cshtml 功能。

Update 1更新 1

1) When I try to create a new asp.net core project and then add js code in Viewstart.cshtml file, it will not be hit during debugging. 1)当我尝试新建一个asp.net核心工程,然后在Viewstart.cshtml文件中添加js代码,调试时不会命中。

To prove it, l create a new single js file and migrate the js code into it.为了证明这一点,我创建了一个新的单个 js 文件并将 js 代码迁移到其中。

After that , reference this js single in cshtml file and then it will be hit during debugging.之后,在cshtml文件中引用这个js单,然后在调试的时候就会被命中。

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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