Brian
Brian

Reputation: 7146

Disabling Hot Reload for .NET Core project in Visual Studio 2019

Some time ago, a Visual Studio update added a hot reload feature. It be handy, but it also can be annoying especially when you're testing and you don't want to reset the current state of the front end. Visual Studio injects the script whether you're debugging or not.

How can hot reload be disabled? My Visual Studio version is 16.10.3

https://devblogs.microsoft.com/visualstudio/speed-up-your-dotnet-and-cplusplus-development-with-hot-reload-in-visual-studio-2022/

Upvotes: 33

Views: 27055

Answers (7)

Eugene
Eugene

Reputation: 421

I use Microsoft Visual Studio Community 2022 (64-bit) - Version 17.9.6. Navigation to the option is different in my case: Tools->Options->Debugging->General, then uncheck Enable Hot Reload. enter image description here

Upvotes: 3

MonkeyDreamzzz
MonkeyDreamzzz

Reputation: 4368

With the CLI you have to do

dotnet watch --no-hot-reload

Upvotes: 11

Shayan Tohidi
Shayan Tohidi

Reputation: 41

I had the same problem, go to Tools > Options > Debugging > General

and check this option Enable edit and continue and hot reload

enter image description here

Upvotes: 4

Anthony Johnston
Anthony Johnston

Reputation: 9604

in VS 2022 open launchSettings.json in the Properties folder

find your profile and add (see arrow, don't add arrow)

{
  "$schema": "https://json.schemastore.org/launchsettings.json",
  "profiles": {
    "Gang.Bingo.Web": {
      "commandName": "Project",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "https://localhost:7249;http://localhost:5249",
      "dotnetRunMessages": true,
      "hotReloadEnabled": false   <===========
    }
  }
}```

Upvotes: 10

Roman Starkov
Roman Starkov

Reputation: 61512

In VS2022, unchecking the "Enable Hot Reload" setting under the projects Debug Properties disables the injection of the aspnetcore-browser-refresh.js script.

These screenshots show one way to access the setting:

Visual Studio debug menu

Visual Studio debug profile

Upvotes: 11

Brian
Brian

Reputation: 7146

This isn't a great solution, but it's a viable workaround.

In the "Network" tab of Chromium Edge's developer tools, I found the request to load aspnetcore-browser-refresh.js. I right click on it and selected "Block URL". This prevents the script from loading.

Upvotes: 8

ShawnOrr
ShawnOrr

Reputation: 1329

You can change this feature here:

Tools > Options > Projects and Solutions > ASP.NET Core > Auto build and refresh option

Options to automatically build and refresh the browser if the web server is running when changes are made to the project.

Your options in this dropdown are the following:

  1. None
  2. Auto build on browser request (IIS only)
  3. Refresh browser after build
  4. Auto build and refresh browser after saving changes

Also note my version of VS is 16.11.1.

Upvotes: 30

Related Questions