27

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/

6 Answers 6

25

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.

4
  • Unfortunately, I don't have this option so I may have to update.
    – Brian
    Aug 28, 2021 at 16:59
  • 7
    I set it to none and even after restarting visual studio it continued to add /_framework/aspnetcore-browser-refresh.js to the bottom of my index.html. Maddening.
    – flyer
    Sep 5, 2021 at 2:34
  • 4
    Yes, unfortunately this setting has no effect even in VS 2022 RTM. Microsoft continues to deny the problem in this support thread: developercommunity.visualstudio.com/t/… I ended up adding a rule to uBlock to block this - under "My filters", add "*aspnetcore-browser-refresh.js*" (no quotes)
    – Andrew
    Nov 10, 2021 at 17:42
  • This suggestion is just plain wrong. It is for control if hot reload is NOT set elswehere Jun 13, 2022 at 20:34
9

With the CLI you have to do

dotnet watch --no-hot-reload
8

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

4
  • Unfortunately this disables .NET hot reload entirely, which is a bit of a heavy-handed approach to preventing the unwanted JS file from being injected into HTML responses.
    – Andrew
    Dec 29, 2021 at 22:45
  • Perhaps heavy-handed in some circumstances, but exactly what I needed to make YARP happy when CSP was being applied (this symptom: Refused to connect to 'ws://localhost:50071/IdentityServer/' because it violates the following Content Security Policy directive: "default-src 'self'". Note that 'connect-src' was not explicitly set, so 'default-src' is used as a fallback.)
    – unbob
    Feb 10, 2022 at 4:10
  • 1
    Can you give some directions instead of a picture? How did you get to Launch Profiles? "Debug" tab at top -> Open your "<my app> Debug Properties" at the bottom of the popup. Mine doesn't have these settings.
    – J_sdev
    Mar 2, 2022 at 1:15
  • just what i was looking for!
    – HelloWorld
    Jan 9 at 20:26
7

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.

1
  • If you're using uBlock, you can also add a filter (under "My filters" in its settings): "*aspnetcore-browser-refresh.js*" (without quotes)
    – Andrew
    Nov 10, 2021 at 17:45
7

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   <===========
    }
  }
}```
2
  • Any idea how to do this for dotnet watch run? The command seems to ignore that, still goes "Hot reload enabled" on startup too. Mar 27, 2022 at 18:08
  • 1
    @Squirrelkiller see my answer Mar 30, 2022 at 7:00
3

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

2
  • The problem with this is that you have to disable both Hot Reload and Edit and Continue. Sep 8, 2022 at 0:52
  • This is the only one that worked for me (VS 2022 17.7.0) Jun 7 at 8:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.