Visual Studio 2017 中的 Javascript 断点 [英] Javascript breakpoints in Visual Studio 2017

查看:36
本文介绍了Visual Studio 2017 中的 Javascript 断点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚安装了 Visual Studio 2017.在启动 ASP.NET MVC 应用程序后,我收到消息说 Visual Studio 中的 chrome 调试已启用.

但我在 Visual Studio 中的断点不会命中.Razor 代码上的断点似乎可以正常工作,但 Javascript 不能.断点没有像应有的那样完全变红.重新启动,重建似乎没有任何效果.

我有以下代码示例

@Html.Partial("_Test", Model.Test)//调试工作在这里<脚本>变量 i = 1;控制台.log(i);//调试在这里或上面不起作用</脚本>@section 脚本 {<脚本>变量 a = 11;控制台.log(a);//调试在这里或上面不起作用</脚本>}

我没有打开 chrome 调试控制台,我检查了 Visual Studio 中已启用的选项('启用 Javascript 调试..').

根据这篇博文,我认为这应该可行:注意 JavaScript 文件中的断点是如何激活的,而 Razor 视图中的断点不是.

我还注意到,在当前 Chrome 会话中第一次加载页面时,在页面加载期间执行 JavaScript 代码时,不会为 JavaScript 文件命中断点.断点仅在文档完成加载一次后才起作用.

I just installed Visual Studio 2017. After starting an ASP.NET MVC application I get the message that chrome debugging in Visual Studio is enabled.

But my breakpoints in Visual Studio won't hit. The breakpoints on Razor code seems to be working but Javascript does not. The breakpoints are not fully red like they should be. A restart, rebuild don't seem to take any effect.

I have the following code example

@Html.Partial("_Test", Model.Test) // debugging works here

<script>
    var i = 1;
    console.log(i); // debugging does not work here or above
</script>

@section scripts {
    <script>
        var a = 11;
        console.log(a); // debugging does not work here or above
    </script>
}

I don't have the chrome debugging console open and I checked the option in Visual Studio ('Enable Javascript debugging..') which is enabled.

According to this blog post I thought this should work: https://blogs.msdn.microsoft.com/webdev/2016/11/21/client-side-debugging-of-asp-net-projects-in-google-chrome/

Am I missing something here? Could it be that this is not working in Visual Studio 2017 somehow?

I only have one extension and that is Resharper, but I guess this is not an issue.

解决方案

This feature does not work for javascript code inside a *.cshtml file, but only for code in separate *.js (or *.ts) files.

Notice how the breakpoint in the JavaScript file is active, while the breakpoint in the Razor view is not.

I have also noticed that breakpoints will not be hit for JavaScript files when JavaScript code is executed during page load when the page is loaded the first time in the current Chrome session. Breakpoints will only work after the document has finished loading once.

这篇关于Visual Studio 2017 中的 Javascript 断点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆