Can I keep an ASP.NET Core web site running after stopping debugging?

Edit the properties for the web site project (right-click in Solution Explorer and select Properties) and then select the Debug tab on the right.

Under Web Server Settings, change Hosting Model to Out of Process.

enter image description here

Now, when debugging is stopped the website should continue to run in IIS Express.

Notes:

  • Tested in Visual Studio 2017 and Visual Studio 2019
  • The default hosting model for VS2017 is "In Process", in case you're wondering.
  • It does not appear to make a difference whether or not you have 'Enable Edit and Continue' selected in Tools > Options > Debugging.

You can start Kestel from the command line and add the watch command. In your project folder run the command:

dotnet watch run

Anytime you save a file in Visual Studio the watch will automatically restart the web server and your pages will show the changes you made.

You can also add a profile to you launchSettings.json and start the profile with Ctrl-F5, or Debug > Start Without Debugging.

"Dotnet Watch": {
  "executablePath": "C:\\Program Files\\dotnet\\dotnet.exe",
  "workingDirectory": "$(ProjectDir)",
  "commandLineArgs": "watch run",
  "launchUrl": "https://localhost:5001;http://localhost:5000",
  "environmentVariables": {
    "ASPNETCORE_ENVIRONMENT": "Development"
  }
}

Lastly, for me anyways, you can add it to your Visual Studio tools. Then you have it available in any projects you are working on.

"Tools > External Tools..."

enter image description here


If you want to edit your app while it runs you have to run it without debugging (ctrl +F5). The point of this is so you can use .net core services like browser link(enabled in development mode), which actually let's you open your app in many browsers at the same time. Your app will run unless you specifically shut it down, for example by closing it through iis express. It uses signal r to keep a connection, but if you make certain changes, for example to the database code, you will have to start it again to see the changes. It is very lightweight, so you don't have to close the app through iis, just retype ctrl and f5 and it will start again.

Remember, your asp.net core app comes with it's own webserver, kestrel. So you can also run it without iis.

In debug mode, the purpose is to analyze your app, for example by setting breakpoints where executions stops so you can look through the stack. This is different than without debugging, because the purpose isn't to change the app on the fly as that would make no sense. You are testing your current version, changing it in debugging mode would potentially obscure other flaws etc.