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

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

问题描述

我刚刚安装了Visual Studio2017.启动ASP.NET MVC应用程序后,我收到一条消息,指出已启用Visual Studio中的chrome调试.

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

我有以下代码示例

@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>
}

我没有打开chrome调试控制台,而是在Visual Studio中选中了已启用的选项(启用Java脚本调试..").

根据此博客文章,我认为这应该可行: 解决方案

此功能不适用于* .cshtml文件中的javascript代码,而仅适用于单独的* .js(或* .ts)文件中的代码./p>

请注意,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天全站免登陆