Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 273
Tom Pažourek Avatar asked Nov 13 '21 07:11

Tom Pažourek


People also ask

How do I disable Browserlink?

Disabling Browser Link There are several ways to disable it: In the Browser Link dropdown menu, uncheck Enable Browser Link. In the Web. config file, add a key named "vs:EnableBrowserLink" with the value "false" in the appSettings section.

Does .NET 6 require Visual Studio 2022?

NET 6 is supported with Visual Studio 2022 and Visual Studio 2022 for Mac. It is not supported with Visual Studio 2019, Visual Studio for Mac 8, or MSBuild 16. If you want to use . NET 6, you will need to upgrade to Visual Studio 2022 (which is also now 64-bit). .

Is .NET 6 the same as .NET Core 6?

Net Core. The latest version of . Net Core is . NET 6.0 and it was released on November 8, 2021.

What is the difference between .NET 6 and .NET Core?

NET Framework to create Windows desktop and server-based applications. This includes ASP.NET web applications. On the other hand, . NET Core is used to create server applications that run on Windows, Linux and Mac.

What is browser link in ASP NET Core?

Browser Link in ASP.NET Core. Browser Link is a feature in Visual Studio that creates a communication channel between the development environment and one or more web browsers.

How do I disable the browser link in Visual Studio?

It is quite easy to disable with the following steps. There are only 3 steps to do this! Go to the browser link toolbar and click the arrow pointing down - shown below. Hit "Enable browser link" so that it no longer has a check mark. Restart Visual Studio after you have done this.

What happens when I re-enable browser link After disabling it?

When you re-enable Browser Link after disabling it, you must refresh the browsers to reconnect them. When CSS Auto-Sync is enabled, connected browsers are automatically refreshed when you make any change to CSS files. Browser Link uses SignalR to create a communication channel between Visual Studio and the browser.

How do I use usebrowserlink in Visual Studio?

The UseBrowserLink call is typically placed inside an if block that only enables Browser Link in the Development environment. For example: For more information, see Use multiple environments in ASP.NET Core. When you have an ASP.NET Core project open, Visual Studio shows the Browser Link toolbar control next to the Debug Target toolbar control:


Video Answer


3 Answers

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

image1

image2

like image 183
tontonsevilla Avatar answered Oct 10 '22 01:10

tontonsevilla


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.

like image 26
Suchiman Avatar answered Oct 10 '22 01:10

Suchiman


More needed to uncheck! enter image description here

This is really hard to unroot feature.

like image 1
Jiří Zídek Avatar answered Oct 10 '22 00:10

Jiří Zídek