ChatGPT解决这个技术问题 Extra ChatGPT

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

In VS 2015 it went like this:

Press start debugging

Website opens in new Chrome tab

Press stop debugging

Website is still open and the site is still running/active

Now in 2017:

Press start debugging

Website opens in new window that can't dock with any other Chrome windows/tabs

Press stop debugging

Website/Chrome window closes, can't continue using the site unless I manually go to the localhost window in Chrome

Is it possible in 2017 to switch back to the 2015 style? So the Chrome/Website window can dock with other Chrome windows/tabs, and it stays open after you stop debugging?

Additionally, I find the new Chrome window frustrating to use, as it seems not to have any history/content available. E.g I can't autocomplete forms or urls, which is very annoying when I'm trying to test a form

For those using Blazor - I found using Opera for debugging solves a lot of these problems.

j
jerone

Visual Studio 2017 version 15.7 and higher & Visual Studio 2019 changed things again.

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):

https://i.stack.imgur.com/qCvfh.png

https://i.stack.imgur.com/Nikvr.png

Tools > Options > Debugging > General

Disable "Enable JavaScript debugging for ASP.NET (Chrome, Edge and IE)".

Tools > Options > Projects and Solutions > Web Projects

(Visual Studio 2017) Disable "Stop debugger when browser window is closed".

(Visual Studio 2019) Disable "Stop debugger when browser window is closed, close browser when debugging stops".


See also this related bug report in the Microsoft Developer Community.
Who the hell added this feature and thought yeah, perfect. It's so annoying!
Please also provide a text solution for when the image is removed etc.
For VS 2019: if anyone's looking for the last option (Stop Debugger when browser window is closed), they've moved it to Tools > Options > Projects and Solutions > Web Projects > Stop debugger when browser window is closed, close browser when debugging stops. See image
@jag Thanks, I included it in the instructions.
M
Mads Kvist Kristensen

The reason for the change in behavior is due to VS 2017's support for debugging JavaScript/TypeScript running in Chrome. See announcement here 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:

https://i.stack.imgur.com/grad1.png


This was not working for me until I deactivated "Enable Edit and Continue" (stackoverflow.com/questions/20831676/…). I think both changes together are the complete solution.
does not works in vs2017, even after disabling Edit and Continue
J
Jean-Sébastien Gervais

For those of you who updated to Visual Studio 2019, that config is now under Tools > Options...

And then in the options dialog (see image below) Projects and Solutions > Web Project :
Uncheck Stop debugger when broswer window is closed, close browser when debugging

https://i.stack.imgur.com/yBNF8.png


To uncheck only this option is not enough. When you close browser, debugger also stops.
@FrenkyB I`m only guessing you need to close and reopen all your visual studio instances as vs debugger is not stopping on my end when I close the browser.
U
Uwe Keim

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'

Tools → Options → uncheck Enable JavaScript debugging for ASP.NET

After doing that when starting debugging chrome opens a new tab, after stopping the tab is not closed but refreshing website shows white screen

again in the Tools → Options

uncheck Enable Edit and Continue

Since now you have your old behaviour back.

https://i.stack.imgur.com/LWRe4.png


with VS 15.7.0 both options are required (before the accapted answer was enough)
@Stefan is correct; you need both options disabled now. But previously it would open a tab, and now opens another instance of the selected browser.
but I need edit and continue for the server side code, why are they intertwined?
@ethermal jerone's answer (Web Projects -> Stop Debugger unchecked) works without disabling Edit and Continue.
Enable Edit and Continue and Hot Reload is selected and greyed out in VS 2022
M
M Komaei

If your project is .net core: in Properties folder > launchSettings.json file set this config :

"launchBrowser": false,

Else in visual studio 2022 : Tools > Options > Projects and Solutions > Web Projects

uncheck : Stop debugger when browser window is closed, close browser when debugging stops

https://i.stack.imgur.com/9cjfy.png


C
Can PERK

Go to Tools -> Options and search for "Stop Debugger". Then select the node Web Projects under Projects and Solutions. Uncheck "Stop debugger when browser window is closed". Before this option your should apply @jerone's suggestion.

PS: This option can be used after VS version 15.7


M
Michael Braude

There are two ways to do this:

Either Launch without debugging by pressing ctrl + f5 or Launch with debugging (pressing f5) and then go to the Debug menu and press "Detach All"

Hope that helps.


I don't think either answer really addresses this awful 2017 workflow / debugging issue. The point is that in 2015 you can launch into an existing Chrome instance and still debug server code in VS. There appears no reasonable way to do this with 2017. You should not have to 'Detach All' every time you launch your app, and close an extra instance of Chrome that pops up, etc. Not giving Michael B. a hard time, just very annoyed with MS about this issue. Hope there is a better solution to get back to the 2015 debugging workflow that made sense.
@Austin, thanks for this feedback. I'll pass it on to the team (I work on Visual Studio at Microsoft)
@MichaelBraude yeah, this is a major step backward in productivity.
As Mads says, you can disable the new behavior if you don't like it. Thank you for this feedback!
yeah, but doing that also disables the chrome debugger.