在VS 2017上停止调试时如何停止浏览器自动关闭

本文翻译自:How to stop browser closing automatically when you stop debugging on VS 2017

I'm trying out the new VS 2017 RC and wondering if anyone knows how to get the previous debugging behavior back 我正在尝试新的VS 2017 RC,想知道是否有人知道如何恢复以前的调试行为

In VS 2015 it went like this: 在VS 2015中,它像这样:

Press start debugging 按开始调试

  • Website opens in new Chrome tab 网站在新的Chrome标签中打开
  • Press stop debugging 按停止调试
  • Website is still open and the site is still running/active 网站仍处于打开状态,并且网站仍在运行/活动

Now in 2017: 现在在2017年:

  • Press start debugging 按开始调试
  • Website opens in new window that can't dock with any other Chrome windows/tabs 网站在新窗口中打开,该窗口无法与其他任何Chrome窗口/标签页对接
  • Press stop debugging 按停止调试
  • Website/Chrome window closes, can't continue using the site unless I manually go to the localhost window in Chrome 网站/ Chrome窗口关闭,除非我手动进入Chrome中的localhost窗口,否则无法继续使用该网站

Is it possible in 2017 to switch back to the 2015 style? 2017年有可能改回2015年风格吗? So the Chrome/Website window can dock with other Chrome windows/tabs, and it stays open after you stop debugging? 因此,Chrome /网站窗口可以与其他Chrome窗口/标签对接,并且在您停止调试后仍保持打开状态吗?

Additionally, I find the new Chrome window frustrating to use, as it seems not to have any history/content available. 此外,我发现新的Chrome窗口令人沮丧,因为它似乎没有可用的历史记录/内容。 Eg I can't autocomplete forms or urls, which is very annoying when I'm trying to test a form 例如,我无法自动完成表单或网址,这在我尝试测试表单时非常烦人


#1楼

参考:https://stackoom.com/question/2ktbz/在VS-上停止调试时如何停止浏览器自动关闭


#2楼

There are two ways to do this: 有两种方法可以做到这一点:

  1. Either Launch without debugging by pressing ctrl + f5 or 通过按Ctrl + F5进行启动而无需调试
  2. Launch with debugging (pressing f5) and then go to the Debug menu and press "Detach All" 通过调试启动(按f5键),然后转到“调试”菜单,然后按“全部分离”

Hope that helps. 希望能有所帮助。


#3楼

The reason for the change in behavior is due to VS 2017's support for debugging JavaScript/TypeScript running in Chrome. 行为更改的原因是由于VS 2017支持调试在Chrome中运行的JavaScript / TypeScript。 See announcement here https://blogs.msdn.microsoft.com/webdev/2016/11/21/client-side-debugging-of-asp-net-projects-in-google-chrome/ 在此处查看公告https://blogs.msdn.microsoft.com/webdev/2016/11/21/client-side-debugging-of-asp-net-projects-in-google-chrome/

To return to the 2015 behavior where Chrome is not closed by the debugger, disable the IE/Chrome script debugger in Tools -> Options like so: 要返回调试器未关闭Chrome的2015年行为,请在“工具”->“选项”中禁用IE / Chrome脚本调试器,如下所示:

在VS 2017上停止调试时如何停止浏览器自动关闭


#4楼

I am writing this answer as I think the previous ones cover only half of the problem. 我正在写此答案,因为我认为以前的答案仅解决了一半问题。

First thing you want is to get rid of this annoying 'run chrome as a new window and auto-close when stopped debugging' 您想要做的第一件事就是摆脱这种烦人的“将chrome作为新窗口运行并在停止调试时自动关闭”

Tools → Options → uncheck Enable JavaScript debugging for ASP.NET 工具→选项→取消选中为ASP.NET启用JavaScript调试

After doing that when starting debugging chrome opens a new tab, after stopping the tab is not closed but refreshing website shows white screen 完成此操作后,Chrome启动调试时会打开一个新标签页,停止后该标签页未关闭,但刷新网站后显示白屏

again in the Tools → Options 再次在工具→选项中

uncheck Enable Edit and Continue 取消选中启用编辑并继续

Since now you have your old behaviour back. 从现在开始,您恢复了以前的行为。

在VS 2017上停止调试时如何停止浏览器自动关闭


#5楼

Visual Studio 2017 version 15.7 and higher & Visual Studio 2019 changed things again. Visual Studio 2017版本15.7和更高版本以及Visual Studio 2019再次更改了功能。

Disabling the following checkboxes will allow you to keep the browser open (doesn't close after stop debugging) and opens another tab (instead of another window): 禁用以下复选框将使您保持浏览器打开(停止调试后不会关闭)并打开另一个选项卡(而不是另一个窗口):

在VS 2017上停止调试时如何停止浏览器自动关闭

在VS 2017上停止调试时如何停止浏览器自动关闭

Tools > Options > Debugging > General 工具>选项>调试>常规

  • Disable "Enable JavaScript debugging for ASP.NET (Chrome, Edge and IE)". 禁用“为ASP.NET(Chrome,Edge和IE)启用JavaScript调试”。

Tools > Options > Projects and Solutions > Web Projects 工具>选项>项目和解决方案> Web项目

  • ( Visual Studio 2017 ) Disable "Stop debugger when browser window is closed". Visual Studio 2017 )禁用“关闭浏览器窗口时停止调试器”。
  • ( Visual Studio 2019 ) Disable "Stop debugger when browser window is closed, close browser when debugging stops". Visual Studio 2019 )禁用“在关闭浏览器窗口时停止调试器,在调试停止时关闭浏览器”。

#6楼

Go to Tools -> Options and search for " Stop Debugger ". 转到工具 -> 选项,然后搜索“ 停止调试器 ”。 Then select the node Web Projects under Projects and Solutions. 然后在“项目和解决方案”下选择“ Web项目”节点。 Uncheck " Stop debugger when browser window is closed ". 取消选中“ 关闭浏览器窗口时停止调试器 ”。 Before this option your should apply @jerone 's suggestion. 在此选项之前,您应该应用@jerone的建议。

PS: This option can be used after VS version 15.7 PS:VS 15.7版之后可以使用此选项