简体   繁体   English

Visual Studio 2013无法在cshtml中调试javascript

[英]Visual Studio 2013 can't debug javascript in cshtml

I have an ASP.NET Web Application created with Visual Studio 2013. I am attempting to debug JavaScript in a CSHTML file. 我有一个使用Visual Studio 2013创建的ASP.NET Web应用程序。我正在尝试在CSHTML文件中调试JavaScript。 However, whenever I launch the webpage, any breakpoint turns into a red circle arrow and states, "The breakpoint will not currently be hit. No executable code of the debugger's target code type is associated with this line. Possible causes include: conditional compiliation, compilier optimizations, or the target architecture of this line is not supported by the current debugger code type." 但是,每当我启动网页时,任何断点都会变成一个红色圆圈箭头并指出“断点当前不会被命中。调试器的目标代码类型的可执行代码与此行没有关联。可能的原因包括:条件编译,目前的调试器代码类型不支持编译器优化或该行的目标体系结构。“

Recently, the project was switched over to support MVC and RAZR, neither of which I know well, and this is exactly when this issue began. 最近,该项目被转换为支持MVC和RAZR,我都不知道,这正是这个问题的开始。 However, searching those have yielded results that don't fix my issue. 但是,搜索那些已经产生的结果无法解决我的问题。

Web.config: Web.config文件:

<compilation debug="true"...>

I know I can debug JavaScript with Firebug or some other browser tool, but I would much rather stick with Visual Studio's debug as that is what I am used to. 我知道我可以使用Firebug或其他一些浏览器工具调试JavaScript,但我更愿意坚持使用Visual Studio的调试,因为这是我习惯的。

So, apparently this is a "known issue" that will be fixed as soon as possible. 所以,显然这是一个“已知问题”,将尽快修复。 A temporary work around that works for "some" people is making sure any Javascript is in a separate file. 对“某些”人工作的临时工作是确保任何Javascript都在一个单独的文件中。

It is caused by having RAZR and Javascript in the same file and Visual Studio 2013 not being able to handle debugging in that instance. 这是因为在同一个文件中使用RAZR和Javascript,而Visual Studio 2013无法在该实例中处理调试。

I don't know what your particular problem is, but if you want to force a debug breakpoint to always happen, add debugger; 我不知道你的具体问题是什么,但如果你想强制调试断点总是发生,添加debugger; to the line that you want it to stop on, and it will stop. 到你希望它停止的那一行,它将停止。 This is regardless of where the JS is located (in a .js file, .html, cshtml, etc.) 这与JS所在的位置无关(在.js文件,.html,cshtml等中)

Here is a blog post about it: 这是一篇关于它的博客文章:

http://sumitmaitra.wordpress.com/2013/12/11/quickbytes-visual-studio-2013-and-javascript-debugging/ http://sumitmaitra.wordpress.com/2013/12/11/quickbytes-visual-studio-2013-and-javascript-debugging/

I also agree that JS should go in a .js file (which I've never had a problem adding a break point in a .js file), but for quick prototyping, this is a solution you can use. 我也同意JS应该进入.js文件(我在.js文件中添加断点时从未遇到过问题),但是对于快速原型设计,这是一个可以使用的解决方案。

If that still doesn't work, you can always you the F12 tools 如果仍然无效,您可以随时使用F12工具

The only browser that allows debugging a javascript file from Visual Studio is Internet Explorer. 允许从Visual Studio调试javascript文件的唯一浏览器是Internet Explorer。 (this is what I found out after testing my application on different browsers) (这是我在不同浏览器上测试我的应用程序后发现的)

I put my javascript in a separate file and debug with IE otherwise it will not work. 我将我的javascript放在一个单独的文件中并使用IE调试,否则它将无法正常工作。

For some reason chrome doesnt allow you to step into the javascript. 由于某种原因,chrome不允许你进入javascript。

One additional thing to check. 还有一件事需要检查。 If you have a App_Start|BundleConfig.cs (which came with MVC 4 - or maybe 3), set BundleTable.EnableOptimizations to false (or, like I did, wrap it in an #if !DEBUG #endif and take the default setting). 如果您有一个App_Start | BundleConfig.cs(随MVC 4一起提供 - 或者可能是3),请将BundleTable.EnableOptimizations设置为false(或者像我一样,将其包装在#if!DEBUG #endif并采用默认设置) 。

I tried and failed to use Chrome and then IE and ended up using the Firebug addon in Firefox, and I was able to debug and set breakpoints in my JS with no problems (in an MVC6 app on Visual Studio 2015 where this is apparently still an issue?!)... 我尝试并且未能使用Chrome然后使用IE并最终在Firefox中使用Firebug插件,我能够在我的JS中调试和设置断点而没有任何问题(在Visual Studio 2015上的MVC6应用程序中,这显然仍然是问题?!)...

FYI - When I tried to debug my JS in Chrome using the F12 Developer Tools, it told me it was not an option as the Debugger was already attached to another process... 仅供参考 - 当我尝试使用F12开发人员工具在Chrome中调试我的JS时,它告诉我这不是一个选项,因为调试器已经附加到另一个进程...

For people coming here in 2017, I want to share that I had this same issue with VS2017 Enterprise RC , and with VS 2015 Community with any browser but Internet Explorer . 人们来到这里在2017年,我想分享, VS2017企业RC 同样的问题 ,并与2015年VS社区任何浏览器,但IE浏览器 Using IE did the trick for me. 使用IE为我做了诀窍。

Also, in VS2017, I had to add a debugger statement to get VS start looking at debug points . 另外,在VS2017中, 我不得不添加一个 debugger 语句来让VS开始查看调试点

Finally, I'd like to ask at least a comment from people voting down. 最后,我想问至少投票的人的评论。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM