問題描述
我剛剛安裝了 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 斷點的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!