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.
I had the same issue. I followed the instructions from the same post: https://blogs.msdn.microsoft.com/webdev/2016/11/21/client-side-debugging-of-asp-net-projects-in-google-chrome/
I did the following in Visual Studio: Go to
Tools
->Options
->Debugging
->General
and turned off the setting "Enable JavaScript Debugging for ASP.NET (Chrome and IE)". Saved changes, then run the webpage.After this, I noticed that Chrome was not showing the "Debug webpage" before loading my page. Then i closed my webpage and stopped the debugging session.
I re-enabled the "Enable Javascript Debugging for ASP.NET (Chrome and IE)" option, then run the webpage using IE, and it worked. The page stopped and the breakpoint showed up in my visual studio.
My best guess here (at least in my case, potentially in your case as well) is that it has to do with bundling. The project I'm working on right now bundles separate scripts into one Big Daddy script (without minifying in debug configuration) so my hunch is that VS won't map my breakpoint to that ultimate script run in the browser.
I know this doesn't answer the question since it's just a hunch, but I'm hoping it points us in the right direction. Maybe if we can validate this against others' experience this could evolve into a real answer.
Another tip: js debug only can be enabled after setting 'start URL' on run/debug.
Only in this way VS will attach to browser process.
I had the same issue, new to .net core, a solution that worked for me was to add debugger; at the top of the script:
For those who use Google Chrome Portable (or added chrome to browsers debug list manually) helps this:
https://docs.microsoft.com/en-us/visualstudio/javascript/tutorial-nodejs-with-react-and-jsx?view=vs-2017#set-and-hit-a-breakpoint-in-the-client-side-react-code
You need to attach then to proper chrome instance manually and viola