Visual Studio 2017 中的 Javascript 断点

Javascript breakpoints in Visual Studio 2017(Visual Studio 2017 中的 Javascript 断点)
本文介绍了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 断点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
Ordinals in words javascript(javascript中的序数)
getFullYear returns year before on first day of year(getFullYear 在一年的第一天返回前一年)