How to disable Browser Link in ASP.NET Core (.NET 6, VS 2022)
Asked Answered
S

4

45

I have disabled Browser Link inside Visual Studio 2022, and I have also disabled all the Hot Reload functionality.

Enable Browser Link is unchecked

Hot Reload settings are disabled

Even the Browser Link Dashboard indicates it should be disabled:

Browser Link Dashboard

I also do not use any of the app.UseBrowserLink(); code anywhere in my code. (as documented in Browser Link in ASP.NET Core.

However, these middlewares still somehow appear in the request pipeline:

  • Microsoft.AspNetCore.Watch.BrowserRefresh.BrowserRefreshMiddleware
  • Microsoft.WebTools.BrowserLink.Net.BrowserLinkMiddleware

These middlewares add this to my HTML:

<!-- Visual Studio Browser Link -->
<script type="text/javascript" src="https://localhost:44399/0928d478a97d441187231f2a1a7cd5e5/browserLink" async="async" id="__browserLink_initializationData" data-requestId="c94cf93088fb44e98f4e499b20ad7bfe" data-requestMappingFromServer="False"></script>
<!-- End Browser Link -->

<script src="/_framework/aspnetcore-browser-refresh.js"></script></body>

And every time I save a file, it reloads the browser. I want to stop this behaviour, and I ran out of options how.

Is this something that the IIS Express or Visual Studio add automatically?

I also checked all the packages and DLLs, and I don't see it included anywhere in my code. It must be included automatically via some "magic" that Visual Studio 2022 does.

How do I stop all this reloading? I do not want any Browser Link or Browser Refresh. Please help, I spent a lot of time on this, and I'm desperate.

Suspect answered 13/11, 2021 at 7:44 Comment(3)
Some days I spend more time trying to disable BrowserLink than I do coding...Hogue
This might be a duplicate question. None of these answers worked for me. I used this answer and it was easy and worked perfectly. https://mcmap.net/q/374599/-how-to-stop-browserlink-js-and-aspnet-core-browser-refreshSprawl
Does this answer your question? How to stop browserlink.js and aspnet-core-browser-refreshSprawl
N
45

You are almost there. You just need to also config the following (Don't forget to restart your VS):

image1

image2

Nosey answered 14/11, 2021 at 3:44 Comment(3)
Hmm so no way to keep the good old Edit & Continue on if I want to get rid of this script...Pressor
I also had to remove the "inspectUrl" property from the project launchSettings.json config file to have it finally stop injecting the Visual Studio Browser Link script into each page. +1Nib
In VS 2022 I found that disabling CSS Hot Reload is sufficient. I was able to leave the other settings as-is. The problem I was trying to solve was that every time I stepped into code, it would jump into the browserlink.js file. I may submit this as a bug to MS.Refute
I
10

Visual Studio uses .NET Core's Startup Hook feature to inject those middlewares, if you set a breakpoint on the first line of your Program.cs and evaluate System.Environment.GetEnvironmentVariable("DOTNET_STARTUP_HOOKS") in the debugger, you can see which hooks are getting loaded from where. If you now go and rename the files it's trying to load, it won't be able anymore to do that and you're free from browserLink!.

For example, in my case, it was loading

"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\Extensions\Microsoft\Web Tools\Browser Link\Microsoft.WebTools.BrowserLink.Net.dll"
"C:\Program Files\dotnet\sdk\6.0.201\DotnetTools\dotnet-watch\6.0.201-servicing.22124.17\tools\net6.0\any\middleware\Microsoft.AspNetCore.Watch.BrowserRefresh.dll"

so i renamed them, adding a _ in front of them which made the script injection disappear.

Indicatory answered 11/4, 2022 at 15:18 Comment(0)
H
3

Because it seems Microsoft can't release a patch to Visual Studio without it including a new setting to disable BrowserLink, try setting the new Auto build and refresh option to None:

enter image description here

Hogue answered 17/4, 2023 at 14:21 Comment(0)
E
2

More needed to uncheck! enter image description here

This is really hard to unroot feature.

Erlene answered 14/6, 2022 at 9:1 Comment(1)
Note: there appears to be a bug here in the Options dialog (I'm using VS2022 17.2.3). If you check these OFF and switch to another 'tab' (such as XAML Hot Reload) then they revert to their previous state. Turn them OFF, click OK and then go back and check!Unleash

© 2022 - 2024 — McMap. All rights reserved.