visual studio 2019 or 2022, Edge Browser for javascript debugging stops at wrong line

问题描述 投票:0回答:3

使用 VS 2019 或 2022 社区版,我可以很好地使用 IE 调试 javascript,但是当使用 Chrome 或 Edge (chromium) 时,断点处显示错误的代码行。突出显示的代码行比实际行低 50 行左右。

对于这个 html 文件,断点出现在“调试器”下方 5 行;

使用此 html 文件,断点正确出现在“调试器”上;

有什么想法吗?这两个 html 文件在 IE 中都能正常工作,但在 Edge 中不能。 使用 Visual Studio Community 2019 版本 16.11.6

这是一个经过验证的问题。请参阅:https://developercommunity.visualstudio.com/t/Edge-Browser-for-javascript-debugging-st/1628778 了解更多信息,如果这对您有影响,请在此处添加评论让 Microsoft 知道我不是唯一一个。似乎他们认为这是一个低优先级

c# debugging visual-studio-2019 microsoft-edge
3个回答
0
投票

对于 Chrome,请执行以下操作:

1)如果您的VS有任何其他扩展,请在Extensions-->Manage Extensions

下禁用任何其他已安装的扩展

2)尝试在工具-->导入和导出设置-->重置所有设置-->常规

下重置所有设置

3)关闭VS,删除

C:\Users\xxx\AppData\Local\Microsoft\VisualStudio\16.0_xxxx\ComponentModelCache

下的组件缓存

4)删除解决方案文件夹下的

.vs
隐藏文件夹,
bin
obj
文件夹

5)之后,重启你的项目,在Tools-->Options-->Debugging-->下勾选Enable Javascript debuggigg for Asp.Net(Chrome,Edge and IE)选项一般

6) 尝试 clean Chrome 缓存 然后再次测试。

如果仍然没有帮助,请尝试将其更新到最新版本或在Chrome上重置设置.

另外,你也可以新建一个asp net工程,测试一下新工程是否有问题。


0
投票

来自https://developercommunity.visualstudio.com我找到了答案(但还不是解决方案):

作者:Raghav Katyal [MSFT]3/12/2021

感谢您的反馈。 Visual Studio 当前不支持在 aspx 和 cshtml 文件中设置调试断点。我们目前的建议是将脚本分解为单独的 .js 文件,以便能够在这些文件中调试脚本。

我们使用客户的反馈来确定功能的优先级,并将此反馈项作为我们的优先级排序流程的输入,以便我们继续改进 Visual Studio。

Steve Zimmelman 2021 年 3 月 16 日:

感谢您的回复。您确实是对的,IE 调试器确实支持这种情况,但 Edge/Chrome 调试器不支持。

也就是说,我们目前正在研究为所有浏览器启用 aspx 和 cshtml 嵌入式 JS 调试。在那之前,请使用 IE 调试器来嵌入 JS。

Edge/Chrome 调试应该使用单独的 js 文件。您附加的日志在 aspx 文件中设置了断点。如果您可以使用单独的 js 文件重现问题并重新发布记录和日志,我们很乐意调查。


0
投票

下面的渲染覆盖有帮助,但并不总是有效,并且可能导致副作用,所以我删除了它。相反,我从我的 MasterPage 中删除了标签之间不需要的空行,然后在第一行之后的 aspx 页面顶部添加了额外的行(<%@ Page Title.....) and before the first

一旦你确定了所需的行数,将它们添加到你正在调试的任何 aspx 页面的顶部,Visual Studio 应该停在“调试器”行..

---旧答案--- 我已经能够重写 Render 以主要纠正问题。它并不完美,但对于大多数 javascript 源(有些可能不在线或两行)来说它是有效的。我创建了一个继承自 System.Web.UI.Page 的 MyPage 类,并添加了下面的代码。您所有的 aspx.cs 页面都需要从 MyPage 继承。

基本上消除了换行,基本上避免了问题。 “IsDevelopmentSite”是我的应用程序中的一个变量,用于标识我正在开发计算机上工作,因此它仅在开发中运行。

        protected override void Render(HtmlTextWriter writer)
        {
            StringBuilder sb = new StringBuilder();
            HtmlTextWriter tw = new HtmlTextWriter(new System.IO.StringWriter(sb));
            base.Render(tw);
            string sContent = sb.ToString();

            if (IsDevelopmentSite && Request.Browser.Browser != "InternetExplorer")
            {
                var headEnd = sContent.IndexOf("</head>");
                if (headEnd > -1)
                {
                    string head = sContent.Substring(0, headEnd);
                    int script;
                    int style;
                    int start;
                    int end;
                    string h = "";
                    do
                    {
                        // remove all cr lf, outside <script> and <style> tags, and some cr lf within script and style.
                        script = head.IndexOf("<script");
                        style = head.IndexOf("<style");
                        if (style == -1 && script == -1)
                            break;

                        if (style == -1 || (script != -1 && script < style))
                        {
                            start = script;
                            end = head.IndexOf("</script>", start) + 9;

                            if (end < 9)
                                break; // no closing tag
                            h += head.Substring(0, start).Replace("\r\n", " ") + head.Substring(start, end - start).Replace(">\r\n", ">");
                        }
                        else
                        {
                            start = style;
                            end = head.IndexOf("</style>", start) + 8;
                            if (end < 8)
                                break; // no closing tag
                            h += head.Substring(0, start).Replace("\r\n", " ") + head.Substring(start, end - start).Replace("\r\n\r\n", "\r\n").Replace("\">\r\n", "\">");
                        }
                        head = head.Substring(end);
                    } while (true);
                    sContent = h + head + sContent.Substring(headEnd);
                }
            }
            writer.Write(sContent);
        }
© www.soinside.com 2019 - 2024. All rights reserved.